Is it possible to give “if-else” condition in LINQ Where clause?
Interviews1 answer
LINQ Question if-else in where clause
1 Answer
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);
ELANGOVAN VENKATACHALAPATHYPosted Feb 16, 2023, 7:51 AM EST
