【发布时间】:2019-02-06 18:35:19
【问题描述】:
我需要做一个这样的界面:
public interface ISomething
{
List<T> ListA { get; set; }
List<T> ListB { get; set; }
}
然后像这样实现它:
public class Something01: ISomething
{
public List<string> ListA { get; set; }
public List<Person> ListB { get; set; }
}
或者像这样:
public class Something02: ISomething
{
public List<int> ListA { get; set; }
public List<string> ListB { get; set; }
}
但是看着other posts 似乎我必须在我的接口类顶部定义 T 。这迫使我在实施时为所有属性使用一种特定类型。这可以以某种方式完成吗?
谢谢
【问题讨论】:
-
您也可以将接口设为泛型:
public interface ISomething<T>,但您需要 2 个泛型类型才能满足您的需求。
标签: c#