-

A simple demonstration of how Enumerable works. I assume that you have knowledge about;

  1. Extension method
  2. Function delegate
Consider the following example;

Let’s filter person class having person.Age greater than 3.
  1. public class Person
  2. {
  3. public int Age;
  4. }
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Func<Person, bool> ff = sady;
  10. Person[] ee = new Person[]
  11. {
  12. new Person { Age = 1 },
  13. new Person { Age = 2 },
  14. new Person { Age = 3 },
  15. new Person { Age = 4 },
  16. new Person { Age = 5 }
  17. };
  18. IEnumerable<Person> pa = ee.Where(sady);
  19. //(or) IEnumerable<Person> pa = ee.Where(ff);
  20. // (or)IEnumerable<Person> pa = ee.Where(s=>s.Age >3);
  21. foreach (Person item in pa)
  22. {
  23. Console.WriteLine(item.Age);
  24. }
  25. Console.Read();
  26. }
  27. public static bool sady(Person a)
  28. {
  29. if (a.Age > 3) return true;
  30. else return false;
  31. }
  32. }
  33. output is
  34. 4
  35. 5
So you are passing the person class and the action (a.Age > 3) that should be performed on each individual variable.

So IEnumerable check the condition as per user requirement and group the result that satisfies the condition and return to user.

Summery

IEnumerable actually applies the filter that is given as parameter by function delegate ( Func< Person, Boolean>) for each items in the collection and then groups the result that passes the condition then returns the result to user.
  1. IEnumerable<Person> pa = ee.Where(s=>s.Age >3);
(s=>s.Age >3) this is Lambda expression that takes one input of type int and return bool.