Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

LINQ with IENUMERABLE in C#

IEnumerable is generally used with LINQ. It specifies that the underlying type implements the GetEnumerator method. It enables the foreach-loop to be used.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ForgetCode
  6. {
  7. public class MainClass
  8. {
  9. public static void Main()
  10. {
  11. IEnumerable<int> result = from value in Enumerable.Range(0, 2)
  12. select value;
  13. foreach (int value in result)
  14. {
  15. Console.WriteLine(value);
  16. }
  17. }
  18. }
  19. }


Output:
0
1