I have a schema of interfaces like the following (C# .NET4)
interface A
{
}
interface B
{
List<A> a;
}
interface C
{
List<B> b;
}
and I implemented it in this way:
public interface A
{
}
public interface B<T> where T : A
{
List<T> a { get; set; }
}
public interface C<T> where T : B
{
List<T> b { get; set; } // << ERROR: Using the generic type 'B<T>' requires 1 type arguments
}
I don’t know how to avoid the error Using the generic type ‘B’ requires 1 type arguments
Since
interface B<T>is generic, you need to provide a formal type argument for it when declaringinterface C<T>. In other words, the current problem is that you are not telling the compiler what type of interface B interface C “inherits” from.The two
Ts will not necessarily refer to the same type. They can be the same type, as inor they can be two distinct types:
The restrictions on the type argument are of course tighter in the first case.