配列に基づいた拡張メソッドを使用していますが、配列をコピーして貼り付ける代わりに、指定したサイズになっていることを確認する簡単な方法があるかどうかを知りたいです。
if array.count != 1000
throw new exception "size of the array does not match"
約 50 の拡張子で
これは私が使用している拡張機能の小さなサンプルです。
<Extension()>
Public Function IsWhite(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.White) = bitPiece.White
End Function
<Extension()>
Public Function IsBlack(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Black) = bitPiece.Black
End Function
<Extension()>
Public Function IsRook(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Rook) = bitPiece.Rook
End Function
<Extension()>
Public Function IsBishop(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Bishop) = bitPiece.Bishop
End Function
<Extension()>
Public Function IsKnight(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.knight) = bitPiece.knight
End Function
<Extension()>
Public Function IsQueen(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Queen) = bitPiece.Queen
End Function
<Extension()>
Public Function IsKing(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.King) = bitPiece.King
End Function
<Extension()>
Public Function IsPawn(ByVal board() As bitPiece, ByVal pos As Integer) As Boolean
Return (board(pos) And bitPiece.Pawn) = bitPiece.Pawn
End Function