简体   繁体   中英

Generic class of a certain base class and also inherit base class

I'm trying to create a simple DataContainer class,

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

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

...but if I want DataContainer to also inherit DataObject - how do I do that?

What's wrong with

[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 }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM