Is there an implicit way to tell a generic collection to use the Type of the incoming IEnumerable<T> data?
Assume any Type can be incoming because it might have been obscured, for example, through IQueryable and might contain an anonymous Type.
var enumerableThings = //... enumerable<T> obtained from somewhere.
The point is T is unknown.
I want to create a List<T> of the primary Type of the enumerable thing:
var listOfThoseThings = new List<???>(enumerableThings);
There are many interesting mechanisms in C#/.NET. I wouldn’t be surprised to find the ability to carry out this task; however at the moment a concise way evades me.
This is why the
ToList()extension method exists.Unlike the
List<T>constructor, it can use type inference to implcitly specify the generic parameter.