What is the output of below code?

List<int> lst = new List<int>();

int index = lst.IndexOf(1);

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

Output will be 0.As we know that IndexOf method returns 0 if it finds the suitable match or particular value.And here List have 2 items i.e. 1 and 2.So IndexOf will search 1 in list.Therefore it will return 0 because 1 is there in List.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response