What is the use of IndexOf method in List collection?

 Posted by Rajesh_Kumar on 1/18/2014 | Category: C# Interview questions | Views: 1966 | Points: 40

IndexOf method is same as String IndexOf method in DotNet.As we know that,IndexOf method is used for searching particular value or text from within string.So it performs same thing with the generic List.It searches List collections and determines the item index of a certain value in the List collection.By using the IndexOf method,we can search for the first position of the value specified in a List collection.
It returns 1 if it finds particular elements in a List otherwise -1 will be returned.


lst.IndexOf("search any text");

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response