Retrieving objects from ArrayList - cast to type?

后端 未结 3 1460
说谎
说谎 2021-01-27 08:36

I\'m taking a basic course in C# programming, and this is a part of our assignment. Very new to programming so I feel more than a bit lost with this.

The assignment is t

3条回答
  •  忘了有多久
    2021-01-27 09:27

    You can use linq to do this easily:

    This will cast all items to string and return an IEnumerable. It will fail if any items can't be cast to a string:

    items.Cast();
    

    This will cast all items that can be to a string and skip over any that can't:

    items.OfType();
    

提交回复
热议问题