Get all items of a certain type from a List of abstract type

后端 未结 5 1908
执笔经年
执笔经年 2021-01-29 03:27

I have a List<> of abstract objects that contains different types of objects. I am trying to grab all the items of a certain type and set th

5条回答
  •  隐瞒了意图╮
    2021-01-29 04:22

    A good old loop should be fine :

    List res = new List();
    foreach(var item in myAbstractItems)
    {
      itemTypeA temp = item as itemTypeA;
      if (temp != null)
        res.Add(temp)
    }
    

提交回复
热议问题