【发布时间】:2014-11-20 03:43:51
【问题描述】:
我是 C# 的新手。
我有一个名为“board”的二维数组:
short[,] board = new short[8,8];
我正在使用一个名为“color”的函数,如果一个白色棋子在正方形 [i,j] 上返回“白色”,如果黑色棋子在正方形 [i,j] 上返回“黑色” , 如果正方形 [i,j] 为空,则为“无”。
if(color[board[i,j]]==White)
{
do something
}
static string color(short[,,,,] t)
{
string Color;
if(t[m,n]==X)
{
Color=None;
}
if(t[m,n]==WP || t[m,n]==WN || t[m,n]==WB || t[m,n]==WR || t[m,n]==WQ || t[m,n]==WK)
{
Color=White;
}
if(t[m,n]==BP || t[m,n]==BN || t[m,n]==BB || t[m,n]==BR || t[m,n]==BQ || t[m,n]==BK)
{
Color=Black;
}
return Color;
}
X, WP, BP, WN, BN, etc..., 只是我之前声明的代表棋子的东西:X=Nothing, WP=White Pawn, BP=Black Pawn, WN=White kNight , BN=黑骑士等...
但是我不知道怎么写颜色函数。我在哪里声明变量m 和n?我希望它们分别对应变量 i 和 j。
而且我什至不确定如何在 Main.js 中调用该函数。我写color[board[i,j]] 或color[board, i, j] 还是别的什么?
【问题讨论】:
标签: c# arrays function multidimensional-array