Introducing Radical.sh

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

Printing the values from LIST in C#

Using foreach, we can print the vales of a List.

  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace forgetCode
  5. {
  6. class program
  7. {
  8. public static void Main()
  9. {
  10. List<int> list = new List<int>();
  11. list.Add(1);
  12. list.Add(2);
  13. list.Add(3);
  14. list.Add(4);
  15.  
  16. foreach (int i in list)
  17. {
  18. Console.WriteLine(i);
  19. }
  20. }
  21. }
  22. }


Output:

1
2
3
4