【发布时间】:2011-11-07 11:06:15
【问题描述】:
是否可以用自己的定义来扩展 Linq 的查询关键字(例如:select、where 等)?
代码示例使其更清晰:
System.Collections.Generic.List<string> aList =
new System.Collections.Generic.List<string> { "aa", "ab", "ba", "bb" };
// instead of
string firstString = (from item in aList
where item.StartsWith("a")
select item).First();
// would be nice
string firstString = from item in aList
where item.StartsWith("a")
selectFirst item;
// or something else
from item in aList
where item.StartsWith("a")
WriteLineToConsole item;
我认为这是不可能的,但仍然希望 ;)
【问题讨论】:
-
您有什么特别的理由想要这样做吗?
-
三个 400K+ 用户回答了您的问题。去,宰山羊!