I am using below code :
var list = new Collection<ArrayList>
{
new ArrayList
{
1,
"Test1"
},
new ArrayList
{
2,
"Test2"
},
};
In the above code I want to avoid the ArrayList and use the Generics. Is it possible in the above code?
Edit:
Above I have used only two values in one arraylist object, I may have multiple items of int’s and string’s in it.
You can’t mix types in a generic list (unless the generic type is
object, but that equates toArrayListand is just a perversion of generics).But you can create a class that contains a
stringandintand use that as the generic parameter for a generic list.Another alternative, if using .NET 4.0 is to use a
Tuple, though I would rather have a strongly typed class.(untested code):