Reverse a list fully and partially in C#

using System; 
using System.Collections.Generic; 
 
namespace w3reverselist { 
    class w3reverselist { 
 
        static void Main(string[] args) { 
 
            // create the list collection 
            List<string> list = new List<string>() { 
                "abc", "ade", "bac", "cbb",  
                 "abb", "ead", "abb"}; 
 
              // reverse the order of the list 
						  list.Reverse(); 
 
						  // enumerate the contents of the list 
						  Console.WriteLine("---Complete Reverse---") ; 
            foreach (string s in list) {
             Console.WriteLine("List item: {0}", s); 
					} 
 
 	 // reverse a part of the list 
         list.Reverse(1, 5); 
 
	// enumerate the contents of the list again 
	Console.WriteLine("---Range Reverse---"); 
	foreach (string s in list) { 
	            Console.WriteLine("List item: {0}", s); 
	} 
 
	// wait for input before exiting 
	Console.WriteLine("Press enter to finish"); 
        Console.ReadLine(); 
         } 
     } 
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.