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:

https://msdn.microsoft.com/en-us/library/d5x73970.aspx


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

You must specify the second argument:

public static IEnumerable<SomeGenericType<M>> append_list<T, M>(T a, T b) 
     where T : IEnumerable<SomeGenericType<M>>
{
      ...
}