At the moment I use List<int> ints = tuple.Item2.Select(s => s.Value).ToList() but this looks inefficient when tuple.Item2 has 1000’s of items. Any better way to achieve this? except using a for loop.
At the moment I use List<int> ints = tuple.Item2.Select(s => s.Value).ToList() but this looks
Share
The built-in way to convert each element in one
List<T1>and store the result in anotherList<T2>isList<T1>.ConvertAll.Unlike
.Select(...).ToList()or.Cast(...).ToList(), this method knows the list size in advance, and prevents unnecessary reallocations that.ToList()cannot avoid.For this to work,
tuple.Item2must really be aList<int?>. It’s not an extension method, it cannot work on the genericIEnumerable<int?>interface.