ArrayList IndexOf() method with starting index
How to search specified Object, get zero-based index of first occurrence within the range of elements in ArrayList
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | class Program { static void Main(string[] args) { ArrayList colors = new ArrayList() { "Green", "Blue", "Red", "Peru", "Blue", "Salmon" }; Console.WriteLine("ArrayList Elements...."); foreach (string color in colors) { Console.WriteLine(color); } Console.WriteLine("IndexOf(object Blue, startIndex 2)"); Console.WriteLine("Index of 'Blue': " + colors.IndexOf("Blue", 2)); Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 10 11 | ArrayList Elements.... Green Blue Red Peru Blue Salmon IndexOf(object Blue, startIndex 2) Index of 'Blue': 4 |