[英]Implementing generic interface without specifying generic class
我想创建通用接口,并且在实现此接口时不指定通用类
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();
}
}
您不能忽略显式类型参数。 C#不会让你。 您必须为通用超类型中出现的每个类型变量指定一个类型实参。
类型变量(也称为泛型参数 )是某个其他类型的占位符,将在实例化或实现泛型类型时指定该占位符。 编译器不会为您推断类型参数,至少不会在类型声明中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.