What’s the difference between "Length", "Count()" and "Rank" for a .NET array?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Lengthis the property of an array object and using it is the most effective way to determine the count of elements in the array (Array.Length in MSDN documentation).Count()is a LINQ extension method that does effectively the same. It applies to arrays because arrays are enumerable objects. It’s preferred to useLength, becauseCount()is likely to be more expensive (see this question for further discussion and MSDN documentation on Count for reference).Rankis the property that returns the number of dimensions (a different thing entirely). When you declare an arrayint[,] myArray = new int[5,10];, theRankof it will be 2, but it will hold a total of 50 elements (MSDN on Rank property).