Introducing Radical.sh

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

Clearing LIST in C#

The Method clear() will be used to clear the contents 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. //Before clearing
  15. Console.WriteLine("Before clearing: "+list.Count);
  16. list.Clear();
  17. //After clearing
  18. Console.WriteLine("After clearing: "+list.Count);
  19. }
  20. }
  21. }


Output:
Before clearing: 3
After clearing: 0