How can i apply 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
How can i apply 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);