如何从linq获取int值(How to get the int value form the linq)
我该如何解决以下问题:
var xvalue = from cust in list where cust.DisplayString == ((Data)x).CustomerName select cust.Number; int namX = xvalue;How can I resolve the issue below:
var xvalue = from cust in list where cust.DisplayString == ((Data)x).CustomerName select cust.Number; int namX = xvalue;最满意答案
您的查询将始终返回匹配结果的“集合”,即使集合仅返回单个项目。
如果您知道查询将始终只匹配单个项目,则可以使用Single Linq方法:
var xvalue = from cust in list where cust.DisplayString == ((Data)x).CustomerName select cust.Number; int namX = xvalue.Single();Your query will always return a 'collection' of matching results, even if the collection returns just a single item.
If you know that your query will always match just a single item, you can use the Single Linq method:
var xvalue = from cust in list where cust.DisplayString == ((Data)x).CustomerName select cust.Number; int namX = xvalue.Single();更多推荐
发布评论