我正在使用基于数组的扩展方法,我想知道是否有一种简单的方法来检查数组是否有指定的大小,而不是我复制粘贴
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