Search for the specified object and returns the zero-based index of the first occurrence within the entire Collection in CSharp
Description
The following code shows how to search for the specified object and returns the zero-based index of the first occurrence within the entire Collection.
Example
using System;// w w w .jav a2 s.c o m
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Demo
{
public static void Main()
{
Collection<string> myData = new Collection<string>();
myData.Add("A");
myData.Add("B");
myData.Add("C");
myData.Add("D");
foreach( string item in myData)
{
Console.WriteLine(item);
}
Console.WriteLine(myData.IndexOf("D"));
}
}
The code above generates the following result.