반응형
Java만 열심히 하다가 C# 만질일이 있어서 만지던중
다차원 배열 초기화를 하다가 멘붕에 빠졌습니다. '-' ;;;;;;;
'-' 이런 모양의 초기화도 존재할수 있따니!!!! ㅋㅋㅋ 옛날 사람
// Two-dimensional array. int[,] array2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; // The same array with dimensions specified. int[,] array2Da = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } }; // A similar array with string elements. string[,] array2Db = new string[3, 2] { { "one", "two" }, { "three", "four" }, { "five", "six" } }; // Three-dimensional array. int[, ,] array3D = new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } }; // The same array with dimensions specified. int[, ,] array3Da = new int[2, 2, 3] { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 7, 8, 9 }, { 10, 11, 12 } } }; // Accessing array elements. System.Console.WriteLine(array2D[0, 0]); System.Console.WriteLine(array2D[0, 1]); System.Console.WriteLine(array2D[1, 0]); System.Console.WriteLine(array2D[1, 1]); System.Console.WriteLine(array2D[3, 0]); System.Console.WriteLine(array2Db[1, 0]); System.Console.WriteLine(array3Da[1, 0, 1]); System.Console.WriteLine(array3D[1, 1, 2]); // Getting the total count of elements or the length of a given dimension. var allLength = array3D.Length; var total = 1; for (int i = 0; i < array3D.Rank; i++) { total *= array3D.GetLength(i); } System.Console.WriteLine("{0} equals {1}", allLength, total);
출처 : http://msdn.microsoft.com/ko-kr/library/2yd9wwz4.aspx
반응형
'C,C++,WinApi,MFC' 카테고리의 다른 글
C# 웹 크롤링 HtmlAgilityPack 특정 한글만 깨지는 경우 (0) | 2024.06.07 |
---|---|
[C#] 다중폼에서 상위 폼 외엔 클릭이나 이벤트 발생 안되게 하기 (0) | 2014.06.27 |
[C#][LitJSON] JsonData에 해당 key가 존재하는지 체크하는 함수 (0) | 2013.08.08 |
winapi, MFC 버튼클릭시 해당홈페이지 익스플로러 띄우기 (6) | 2010.02.10 |
라이브러리 추가시 유용한 #pragma comment() (0) | 2010.02.03 |