Mega Code Archive

 
Categories / C# / Collections Data Structure
 

Search for the first occurrence of the duplicated value

using System; using System.Collections; public class SamplesArrayList {     public static void Main()       {         ArrayList myAL = new ArrayList();         myAL.Add( "the" );         myAL.Add( "quick" );         myAL.Add( "brown" );         myAL.Add( "fox" );         myAL.Add( "jumps" );         myAL.Add( "over" );         myAL.Add( "the" );         String myString = "the";         int myIndex = myAL.IndexOf( myString );         Console.WriteLine( "The first occurrence of \"{0}\" is at index {1}.", myString, myIndex );     }     public static void PrintIndexAndValues(IEnumerable myList)     {         int i = 0;         foreach (Object obj in myList)             Console.WriteLine("   [{0}]:    {1}", i++, obj);     } }