Reputation: 41
I want to convert Tuple IEnumerable
to a List<string>
. For example, if there is
public static IEnumerable<Tuple<string, Type>> GetWord(String formula)
how can I pass the enumerable directly into the constructor of a new List<string>
???
Thanks!
Upvotes: 4
Views: 1456
Reputation: 32445
With Select
extension method you can convert enumerable of Tuple to the enumerable of string.
And then you can create a List<string>
without explicitly passing enumerable to the List
constructor, but by using ToList
extension method.
var list = GetWord(formula).Select(t => t.Item1).ToList();
Upvotes: 2
Reputation: 81493
Select
is probably what you want
var list = new List<string>(GetWord.Select(x => x.Item1));
Upvotes: 7