c# 基础之数组(包含三维数组)
public enum ChessType { White = 0, None=1, Black=2, } class Program { static void Main(string[] args) { ChessType[,] _data = new ChessType[15, 15]; for (int x = 0; x < 15; x++) { for (int y = 0; y < 15; y++) { Console.WriteLine(_data[x,y]); } } Console.ReadKey(); } }
得到的结果:输出的全部是White
三维数组的案例:
bool[, ,] _cgrades = new bool[15, 15, 572]; int _icount = 0; //横 for (int i = 0; i < 15; i++) { for (int j = 0; j < 11; j++) { for (int k = 0; k < 5; k++) { _cgrades[j + k, i, _icount] = true; Console.WriteLine((j+k)+"-"+i+"-"+_icount+"数字:" + _icount + "---值:" + _cgrades[j + k, i, _icount]); } _icount++; } } //竖 for (int i = 0; i < 15; i++) { for (int j = 0; j < 11; j++) { for (int k = 0; k < 5; k++) { _cgrades[i, j + k, _icount] = true; Console.WriteLine(i+"-"+(j+ k)+"-"+_icount+"数字:" + _icount + "---值:" + _cgrades[i, j + k, _icount]); } _icount++; } } // 右斜 for (int i = 0; i < 15 - 4; i++) { for (int j = 0; j < 11; j++) { for (int k = 0; k < 5; k++) { _cgrades[j + k, i + k, _icount] = true; Console.WriteLine((j + k)+"-"+"-"+ (i+k) +"-"+_icount+"数字:" + _icount + "---值:" + _cgrades[j + k, i + k, _icount]); } _icount++; } } for (int i = 0; i < 11; i++) { for (int j = 15 - 1; j >= 4; j--) { for (int k = 0; k < 5; k++) { _cgrades[j - k, i + k, _icount] = true; Console.WriteLine("数字:" + _icount + "---值:" + _cgrades[j - k, i + k, _icount]); } _icount++; } } Console.WriteLine(_cgrades[4,11,0]); Console.WriteLine();