ICollection-获得单一价值 [英] ICollection - Get single value
本文介绍了ICollection-获得单一价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从ICollection获取价值的最佳方法是什么? 我们知道Collection除此以外是空的.
What is the best way to get a value from a ICollection? We know the Collection is empty apart from that.
推荐答案
Linq,宝贝,是的...
Linq, baby, yeah...
var foo = myICollection.OfType<YourType>().FirstOrDefault();
// or use a query
var bar = (from x in myICollection.OfType<YourType>() where x.SomeProperty == someValue select x)
.FirstOrDefault();
这篇关于ICollection-获得单一价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文