0

In the following statement will the where method iterate through all elements before First is executed on the returned elements, or will the First method take effect already in the Where method? In VB.NET:

Items.Where(Function(Item) Item.IsMatch).First

Items implements IEnumerable(Of T)

SuppaiKamo
  • 285
  • 2
  • 5
  • 16

1 Answers1

1

From MSDN document for Where:

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated.

That is when First() is invoked on Wheres output, which in turn invokes GetEnumerator.

Alireza
  • 4,976
  • 1
  • 23
  • 36