c# - Generic Method where T is List that implements interface -



c# - Generic Method where T is List that implements interface -

this similar c# - multiple generic types in 1 list

however, want generic method take list of objects implement same interface.

this code gives error there no implicit reference conversion.

public interface itest { } public class interfaceuser : itest { } public class testclass { void genericmethod<t>(t mylist) t : list<itest> { } void testgeneric() { genericmethod(new list<interfaceuser>()); } }

can done?

define t itest , take list<t> argument

public interface itest { } public class interfaceuser : itest { } public class testclass { void genericmethod<t>(list<t> mylist) t : itest { } void testgeneric() { this.genericmethod(new list<interfaceuser>()); } }

c# generics

Comments

Popular posts from this blog

c# - Move local mssql database to webhosted MYSQL -

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -