I want to create generic interface and dont specify generic class when I implement this interface
public interface IThis<T>
{
T this[int id] { get; }
}
public class Student : IThis<Student> // i dont want repeat Student in this
{
public Student this[int id]
{
get => new Student();
}
}
You can't omit the explicit type argument; C# won't let you. You must specify a type argument for every type variable that appears in a generic supertype.
A type variable (also called a generic parameter ) is a placeholder for some other type that will be specified when instantiating or implementing a generic type. The compiler won't infer the type arguments for you—at least not in a type declaration.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.