Narayanan Thiyagarajan
LINQ Question if-else in where clause

Is it possible to give “if-else” condition in LINQ Where clause?

By Narayanan Thiyagarajan in LINQ on Jun 23 2020
  • ELANGOVAN VENKATACHALAPATHY
    Feb, 2023 16

    Yes, it is possible to use if-else conditions in a LINQ Where clause using the ternary operator (? :) or the null coalescing operator (??).
    List numbers = new List { 1, 2, 3, 4, 5 };
    int max = 3;
    var filteredNumbers = numbers.Where(n => n <= max ? true : false);

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS