某个基类的泛型类,也继承基类

时间:2012-09-05 12:36:38

标签: c# generics inheritance constraints base-class

我正在尝试创建一个简单的DataContainer类,

public interface DataObject
{
    string Name { get; set; }
    uint ID { get; set; }
}

[Serializable()]
public class DataContainer<T> where T : DataObject
{
}

...但如果我希望DataContainer也继承DataObject - 我该怎么做?

1 个答案:

答案 0 :(得分:3)

有什么问题
[Serializable()]
public class DataContainer<T> : DataObject where T : DataObject
{
    public string Name
    {
        get { //implementation here }
        set { //implementation here }
    }

    public uint ID
    {
        get { //implementation here }
        set { //implementation here }
    }
}