What is the difference between Array.GetLength() and Array.Length?

前端 未结 5 1772
自闭症患者
自闭症患者 2020-12-13 08:51

How do you use the Array.GetLength function in C#?

What is the difference between the Length property and the GetLength functi

5条回答
  •  情书的邮戳
    2020-12-13 09:31

    In mathematical term, we call as m rows and n columns, so the results is product of m*n for a two dimensional array. In this case GetLength(0) = m rows and GetLength(1)= n columns. For e.g see below example

    string[,] stocks ={{"RELIND","Reliance Industries","1006.30"},{"TATMOB","Tata Mobiles","504.10"},{"ALST","Allstate","800.00"}, {"GE","GE Motors","810.00"}
    };
    

    The stocks arrays return GetLength(0)= 4 and GetLength(1)=3 and length =12

提交回复
热议问题