fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. private static readonly List<string> listOne = new List<string> { "one", "1" };
  8. private static readonly List<string> listTwo = new List<string> { "two", "2" };
  9.  
  10. public static void Main()
  11. {
  12. PrintList(listOne);
  13. Foo(listOne);
  14. PrintList(listOne);
  15.  
  16. PrintList(listTwo);
  17. Foo(listTwo.ToList());
  18. PrintList(listTwo);
  19. }
  20.  
  21. private static void Foo<T>(List<T> list)
  22. {
  23. list.Clear();
  24. }
  25.  
  26. private static void PrintList<T>(List<T> list)
  27. {
  28. Console.WriteLine(list.Any() ? string.Join(",", list) : "(empty list)");
  29. }
  30. }
Success #stdin #stdout 0.02s 16672KB
stdin
Standard input is empty
stdout
one,1
(empty list)
two,2
two,2