I'm trying to create a generic list using C# and .NET 4.0
List<var> varlist = new List<var>();
This code produces the error "The contextual keyword 'var' may only appear in a local variable declaration"
The reason being is because I want to do something like this:
List<var> varList = new List<var>(); // Declare the generic list
List<Object1> listObj1; // List of Object1
List<Object2> listObj2; // List of Object2
varList = listObj1; // Assign the var list to list of Object1
varList = listObj2; // Re-assign the var list to the list of Object2
Is there any way to do this in C# .NET 4.0?
objectinstead ofvarList<T>has a few base interfaces that you can reference to them as, some are not generic so will allow you to not care about the type, but then you probably don't want to do type-specific things with it.