What is the best way to convert a non-generic collection to a generic collection? Is there a way to LINQ it?
I have the following code.
public class NonG
Since you can guarantee they're all TestClass instances, use the LINQ Cast
public static List ConvertToGenericClass(NonGenericCollection collection)
{
return collection.Cast().ToList();
}
Edit: And if you just wanted the TestClass instances of a (possibly) heterogeneous collection, filter it with OfType
public static List ConvertToGenericClass(NonGenericCollection collection)
{
return collection.OfType().ToList();
}