开发者

switch case like selection in LINQ-C#

How can i app开发者_运维问答ly switch..case like selection in LINQ ?

choice between this and this select this end

choice between this and this select this end

...

...

choice between this and this select this end

choice between this and this select this end


Here is a simple example:

bool showEven = false;
var query = Enumerable.Range(0, 100);

switch (showEven)
{
    case true: query = query.Where(i => i % 2 == 0); break;
    case false: query = query.Where(i => i % 2 == 1); break;
}

foreach (var item in query)
    Console.WriteLine(item);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜