Using List in C# (Generics)

You need to declare T against the method, then C# can identify the type the method is receiving. Try this:

void MyMethod<T>(List<T> list){
    //Do stuff
}

Then call it by doing:

if (someCondition)
    MyMethod(list1);
else
    MyMethod(list2);

You can make it even stricter, if all classes you are going to pass to the method share a common base class:

void MyMethod<T>(List<T> list) where T : MyClassBase

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)