如何強制使用在類中實作泛型介面的類?這樣的事情可能嗎?
public interface IGeneric<T>
{
T Value {get;}
}
//public class MyList<IGeneric<T>> {}//not allowed
uj5u.com熱心網友回復:
像這樣的東西:
public class MyList<T> where T : IGeneric<T>
{
}
或這個:
public class MyList<T> : IGeneric<T>
{
public T Value => throw new NotImplementedException();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/491900.html
下一篇:LVGL庫入門教程03-布局方式
