Articles → .NET → Deferred And Immediate Execution In LINQ
Deferred And Immediate Execution In LINQ
Deferred Execution
List<string> weekdays = new List<string>();
weekdays.AddRange(new string[]
{ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"});
var weekdayWithT = from element in weekdays where element.StartsWith("t") select element;
foreach (var el in weekdayWithT)
{
MessageBox.Show(el.ToString());
}
Click to Enlarge
Immediate Execution
List<string> weekdays = new List<string>();
weekdays.AddRange(new string[]
{ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"});
int weekdayWithTCount = (from element in weekdays where element.StartsWith("t") select element).Count();
MessageBox.Show(weekdayWithTCount.ToString());
Click to Enlarge