C# List<T> class provides methods and properties to create a list of objects (classes). You can add items to a list during the initialization or using List.Add() and List.AddRange() methods.
List is a generic class. You must import the following namespace before using the List<T> class.
using System.Collections.Generic;
The Reverse method of List<T> reverses the order all items in in the List.
The following code example reverses a List.
  1. // List of string
  2. List<string> authors = new List<string>(5);
  3. authors.Add("Mahesh Chand");
  4. authors.Add("Chris Love");
  5. authors.Add("Allen O'neill");
  6. authors.Add("Naveen Sharma");
  7. authors.Add("Mahesh Chand");
  8. authors.Add("Monica Rathbun");
  9. authors.Add("David McCarter");
  10. Console.WriteLine("Original List items");
  11. Console.WriteLine("===============");
  12. // Print original order
  13. foreach (string a in authors)
  14. Console.WriteLine(a);
  15. // Reverse list items
  16. authors.Reverse();
  17. Console.WriteLine();
  18. Console.WriteLine("Sorted List items");
  19. Console.WriteLine("===============");
  20. // Print reversed items
  21. foreach (string a in authors)
  22. Console.WriteLine(a);
Listing 1.
The output of Listing 8 looks like Figure 1.
Reverse C# List
Figure 1.
Next > C# List Tutorial