Reputation: 2637
I have a collection of List<List<object>>
. I need to convert it to List<List<string>>
.
This is what i tried,
List<List<object>> dataOne = GetDataOne();
var dataTwo = dataOne.Select(x => x.Select(y => y.ToString()).ToList()).ToList();
Is this method fine? Or is there any other best way to do it?
Is there anyway to automatically convert the list without iterating over it, or having the framework iterate over it
Upvotes: 3
Views: 98
Reputation: 823
Your approach is fine, you need to visit all the elements to convert them
however, a cleaner way to do this would be:
var dataTwo = dataOne.ConvertAll(x => x.ConvertAll(obj => obj.ToString()));
Upvotes: 6