开发者

switch case like selection in LINQ-C#

开发者 https://www.devze.com 2022-12-09 13:45 出处:网络
How can i app开发者_运维问答ly switch..case like selection in LINQ ? choice between this and thisselect this end

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

精彩评论

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