Reputation: 18117
I have string array string[] MyArray
. What is the quickest (meaning least code, not fastest performance) way to convert all string array elements to lowercase?
Upvotes: 36
Views: 68755
Reputation: 324
Easiest approach:
MyArray = Array.ConvertAll(MyArray, d => d.ToLower());
Upvotes: 24
Reputation: 8827
myArray = Array.ConvertAll(myArray, x => x.ToLower());
Note: This is very close to 'prasadd' answer but works with string arrays.
Upvotes: 3
Reputation: 8259
I wouldn't use this in production:
MyArray = string.Join(";", MyArray).ToLower().Split(';');
Upvotes: -6
Reputation: 1259
I'd go with
var lowercaseStringArray = myStringArray.Select(c => c.ToLower()).ToArray();
Upvotes: 1
Reputation: 46947
Without creating a new Array.
for (int i = 0; i < MyArray.Length; i++)
MyArray[i] = MyArray[i].ToLower();
Upvotes: 10
Reputation: 43207
strin[] MyArrayLower = (from str in MyArray
select str.ToLower()).ToArray();
Upvotes: 2
Reputation: 241641
var MyArrayLower = MyArray.Select(s => s.ToLowerInvariant()).ToArray();
(or
MyArray = MyArray.Select(s => s.ToLowerInvariant()).ToArray();
if you want to replace the existing array with a new instance of string[]
.)
Upvotes: 67