Created
February 13, 2016 17:52
-
-
Save samirbehara-zz/6b30514606477750eda4 to your computer and use it in GitHub Desktop.
Immediate Execution in LINQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImmediateExecution | |
{ | |
static void Main(string[] args) | |
{ | |
var Employees = new List<Employee> | |
{ | |
new Employee { ID=1 , Name="Samir", Salary=30000 }, | |
new Employee { ID=2 , Name="Robert", Salary=42000 }, | |
new Employee { ID=3 , Name="Peter", Salary=54000 } | |
}; | |
var emp = Employees.Where(x => x.Salary < 35000) | |
.Select(y => y.Name).ToList(); // LINQ Query is constructed and also executed here | |
// Creating another Employee instance after the LINQ Query is constructed | |
Employees.Add(new Employee { ID = 4, Name = "Mark", Salary = 18000 }); | |
foreach (var empName in emp) | |
{ | |
Console.WriteLine(empName); // Output -- Samir | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment