top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Define what is Where clause and Let clause in LINQ?

+3 votes
847 views
Define what is Where clause and Let clause in LINQ?
posted Jun 30, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Where clause: It allows adding some conditional filters to the query.
Let clause: It allows defining a variable and assigning it a value calculated from the data values.

LINQ Query

var objresult = from emp in objEmployee
                            let totalSalary = objEmployee.Sum(sal =>  sal.Salary)
                            let avgSalary = totalSalary / 5
                            where avgSalary > emp.Salary
                            select emp;
answer Jul 4, 2017 by Shivaranjini
0 votes

Where clause: It allows us to add some conditional filters to the query.
Let clause: It allows us to define a variable and assigning it a value calculated from the data values.

 var arr = new[] { 5, 3, 4, 2, 6, 7 };
    var sq = from int num in arr
                    let square = num * num
                    where square > 10
                    select new { num, square };

    foreach (var a in sq)
        Console.WriteLine(a);
answer May 2, 2019 by Siddhi Patel
...