This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
To sort a string array, why is it important to use the String.Trim() method on each array element before sorting?
String.Trim()
Only string arrays with elements trimmed with String.Trim() can sort.
String.Trim() removes leading white space that would sort before numbers and letters.
The array sort is noticeably faster using String.Trim() on each element.
Both foreach and for are good choices to iterate small single dimension arrays like {"cat", "fox", "dog", "snake", "eagle"}, but when is it best to use a for loop?
foreach
for
When the elements have alphabetical sort order.
To perform a search on each element in the array.
To evaluate a specific range of elements.
You must answer all questions before checking your work.
Continue
Was this page helpful?