Skip to content

Instantly share code, notes, and snippets.

@samirbehara-zz
Created February 13, 2016 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samirbehara-zz/6b30514606477750eda4 to your computer and use it in GitHub Desktop.
Save samirbehara-zz/6b30514606477750eda4 to your computer and use it in GitHub Desktop.
Immediate Execution in LINQ
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