[英]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.