如何从linq获取int值(How to get the int value form the linq)

编程入门 行业动态 更新时间:2024-10-25 21:28:17
如何从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();

更多推荐

本文发布于:2023-07-31 01:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340444.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:linq   int   form

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!