Is it possible to give “if-else” condition in LINQ Where clause?
Loading
Is it possible to give “if-else” condition in LINQ Where clause?
Yes, it is possible to use if-else conditions in a LINQ Where clause using the ternary operator (? :) or the null coalescing operator (??).
List
int max = 3;
var filteredNumbers = numbers.Where(n => n <= max ? true : false);