C# StringCollection IndexOf
Description
StringCollection IndexOf
searches for the specified
string and returns the zero-based index of the first occurrence within the
StringCollection.
Syntax
StringCollection.IndexOf
has the following syntax.
public int IndexOf(
string value
)
Parameters
StringCollection.IndexOf
has the following parameters.
value
- The string to locate. The value can be null.
Returns
StringCollection.IndexOf
method returns The zero-based index of the first occurrence of value in the StringCollection,
if found; otherwise, -1.
Example
using System;/* ww w . j a va 2 s.com*/
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.