Kindly let me know the difference between the “where” in (1) and “where()” in (2).
When to use “where” and “where()” ?
List<Person> pList =
new List<Person>
{
new Person
{EmpNo=1,FirstName="Marc",LastName="Loel",Salary=3434},
new Person
{EmpNo=2, FirstName="Steve",LastName="Kaith",Salary=4545},
new Person
{EmpNo=3,FirstName="Neol",LastName="Henk",Salary=2222},
};
(1) var v = from p in pList where p.EmpNo == 1 select new { p.FirstName };
(2) var query =pList .Where(p => p.EmpNo == 1)
.Select(p => new { p.FirstName});
The difference (if you want to be picky) is that the first one is LINQ, and the second one isn’t.
LINQ is the integrated query language that you see in the first example, and the compiler turns it into using the extension methods seen in the second example.