Program Tip

2D 배열의 크기는 어떻게 찾습니까?

programtip 2020. 10. 9. 12:16
반응형

2D 배열의 크기는 어떻게 찾습니까?


이 질문에 이미 답변이 있습니다.

이 배열을 선언하면 ...

string[,] a = {
                  {"0", "1", "2"},
                  {"0", "1", "2"},
                  {"0", "1", "2"},
                  {"0", "1", "2"},
              };

그런 다음 길이를 측정 할 수 있습니다.

a.Length

12입니다. 배열의 차원을 어떻게 측정합니까? 시도하면 ...

a[0].Length

나는 Wrong number of indices inside []; expected 2. 무엇을 제공합니까?


배열의 GetLength () 메서드를 원합니다.

a.GetLength(0);

http://msdn.microsoft.com/en-us/library/system.array.getlength.aspx


사용 Array.Rank사용 후 차원의 번호를하고 Array.GetLength(int dimension)특정 차원의 길이를 얻을 수 있습니다.


System.Array.GetLength (int dimension)을 사용하십시오 .

참고 URL : https://stackoverflow.com/questions/4106369/how-do-i-find-the-size-of-a-2d-array

반응형