Search string and returns the zero-based index of the first occurrence in StringCollection in CSharp
Description
The following code shows how to search string and returns the zero-based index of the first occurrence in StringCollection.
Example
using System;/*from w w w . j av a 2s .c o m*/
using System.Collections;
using System.Collections.Specialized;
public class SamplesStringCollection {
public static void Main() {
StringCollection myCol = new StringCollection();
String[] myArr = new String[] { "A", "B", "C" };
myCol.AddRange( myArr );
Console.WriteLine(myCol.IndexOf( "B" ) );
}
}
The code above generates the following result.