C# Question

How to use generic interface as generic constraint?

I want to use following code (as example):

public static IEnumerable<SomeGenericType> append_list<T>(T a, T b) where T : IEnumerable<SomeGenericType>
return a.Concat(b);

Documentation says that using generic interface constraint is possible:


where T :
The type argument must be or implement the specified interface. Multiple interface constraints can be specified. The constraining interface can also be generic.

But I really don't understand how to make such code to work,

Answer Source

You must specify the second argument:

public static IEnumerable<SomeGenericType<M>> append_list<T, M>(T a, T b) 
     where T : IEnumerable<SomeGenericType<M>>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download