Time for action – running a filter on a range

Assume that you want to find all the numbers in the previously-mentioned range that are multiples of 11. Here is how we can do that using Range() and Where():

  1. Copy the following as a query to LINQPad:
    var multiplesOfEleven = Enumerable.Range(1, 100).Where(c => c % 11 == 0);
    multiplesOfEleven.Dump("Multiples of 11 from 1 to 100");
  2. Run the query and you should get the following output:
    Time for action – running a filter on a range

What just happened?

Range() returned an IEnumerable<int> instance and that was passed to Where() as an input. Thus, Where() operates to find the numbers divisible by 11 and returns only those as the final IEnumerable<Int32> ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.