배열
C#에서의 배열 선언형식
- 데이터형[[] 배열명;
int[] array_name;
@ 생성과 초기화
- int[] array;
array = new int[] {1,2,3};
array = new int[3] {1,2,3};
- int[] array = new int[3] {1,2,3};
int[] array = new int[] {1,2,3};
- int[] array = {1,2,3};
for (int i = 0; i < nArray.Length; i++)
Console.Write("{0}", nArray[i]));
Console.Write('/n');
foreach (int m in nArray)
Console.Write("{0}", m);
Console.Write('/n');
String[] Days = {"sun", "mon", "tue"};
foreach (String str in Days)
console.Write(str + " ");
이차원&다차원 배열
- 행과 열, 면은 콤마(,)로 구분
- 선언형식
데이터형[,] 배열명;
데이터형[,,] 배열명;
int[,] array1 = new int[2,2];
int[,,] array2 = new int[2,3,2];
int[,] array1 = new int[,]{{1,2},{3,4}};
int[,,] array2 = new int[,]{ {1,2},{3,4}},{{5,6},{7,8}} };
------------------------------------------
int[,] array2 = { {1,2},{3,4},{5,6} };
int[,,] array3 ={ {{1,2},{3,4},{5,6}}, {{7,8}{9,10},{11,12}} };