I'm reading from a database and trying to store the current record in an instance of my object. How can I add a new item to my list?
private void Load_data<T>(AseDataReader reader, List<T> table)
{
while (reader.Read())
{
table.Add(new myclass1
{
id_number= SafeGetInt(reader, 0),
state = SafeGetString(reader, 1)
});
}
}
The "table.Add(new myclass1" is the issue for the compiler. More specifically the, "myclass1". I'm new to generics. How can I do this? Is it possible?
Update: Okay so I'm calling the above method when I get to the point in my code that I know what type it needs to be. I'm using a method one level up from this that accepts all list types - so I don't need to have 12 overloaded methods that do the same thing.