c# collection inheritance

前端 未结 3 671
忘掉有多难
忘掉有多难 2021-01-14 23:53

Is there a collection in c# that supports the inheritance like concept that objects can have of appearing to include all the elements from another as well as themselves?

3条回答
  •  长发绾君心
    2021-01-15 00:03

    Thats not that tricky

    // Adding 
    Animals.Add( animal );
    if( animal is dog )
        Dogs.Add( animal );
    
    //Removing 
    Dogs.Remove( animal );
    Animals.Remove( animal );
    

提交回复
热议问题