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);
精彩评论