Example using the LastIndexOf Method in C# List

using System; 
using System.Collections.Generic; 
 
namespace w3LastIndexOf { 
    class w3LastIndexOf { 
 
        static void Main(string[] args) { 
 
            // create the list collection 
            List<string> list = new List<string>() { 
                "abc", "ade", "bac", "cbb",  
                 "abb", "ead", "abb"}; 
 
             // find an item using IndexOf and LastIndexOf 
             int index1 = list.IndexOf("abb"); 
             int index2 = list.LastIndexOf("abb"); 
 
             // write the results 
             Console.WriteLine("IndexOf: {0}", index1) ; 
             Console.WriteLine("LastIndexOf: {0}", index2) ; 
 
             // 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.