ICollection - Get single value

后端 未结 5 881
孤街浪徒
孤街浪徒 2021-02-03 17:45

What is the best way to get a value from a ICollection? We know the Collection is empty apart from that.

5条回答
  •  面向向阳花
    2021-02-03 18:12

    Linq, baby, yeah...

       var foo = myICollection.OfType().FirstOrDefault();
        // or use a query
        var bar = (from x in myICollection.OfType() where x.SomeProperty == someValue select x)
           .FirstOrDefault();
    

提交回复
热议问题