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
Post a Comment