Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which is better for array check? .GetLength or .Length

Status
Not open for further replies.

needscoop

Programmer
Nov 13, 2002
29
US
Determining count of array (1 dim) elements (words within a string) - which is better approach to use: .GetLength(0) or .Length ? Is one approach better than the other, or only marginally?

See code snippet below:

Code:
string[] MyCheck = mystring.TrimStart().Split(' ');

int MyItemsCnt = 0;
						
MyItemsCnt = MyCheck.[B]GetLength(0)[/B] ;
  // [u]or[/u] ???
MyItemsCnt = MyCheck.[B]Length[/B] ;
						
if ( MyItemsCnt > 50 )
   {
   MyItemsCnt = 50;    // caps words in string to 50 max.
   }

... and so on
 
I seldom use multidimensional arrays, so I always use .Length

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top