LINQ:将.Single()转换为查询符号 [英] LINQ: convert .Single() to query notation
本文介绍了LINQ:将.Single()转换为查询符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我知道查询符号
var word = from s in stringList
where s.Length == 3
select s;
等效于点符号
var word = stringList
.Where(s => s.Length == 3)
.Select(s => s);
但是如何将点符号转换为查询符号?
But how do you convert this dot notation to a query notation?
var word = wordsList
.Single(p => p.Id == savedId);
我在Google上找不到太多资源.
I couldn't find much resources on Google.
推荐答案
您不能.许多LINQ函数不能在查询语法中使用.充其量,您可以将两者结合起来并做类似的事情
You can't. A lot of LINQ functions can't be used in the query syntax. At best, you can combine both and do something like
var word = (from p in wordsList
where p.Id == savedId
select p).Single()
,但在 collection.Single(condition)
的简单情况下,点符号"对我来说更容易理解.
but in the simple case of collection.Single(condition)
, the "dot notation" seems more readable to me.
在 MSDN 上,有LINQ使用的关键字列表,您可以从该列表中查看哪些功能已集成到该语言中.
There is a list of keywords used by LINQ on MSDN, you can see which functions are integrated into the language from that list.
这篇关于LINQ:将.Single()转换为查询符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文