index of item in list c# code example
Example 1: c# get index of item in list
Array.IndexOf(arrName, searchingFor)
Example 2: find index of string in a list C#
using System;
using System.Collections.Generic;
public class Program {
public static void Main() {
List < string > myList = new List < string > () {
"Football",
"Soccer",
"Tennis",
};
int index = myList.FindIndex(a => a.Contains("Tennis"));
Console.WriteLine("List Item Tennis Found at index: " + index);
}
}
Example 3: index of item in list C#
List<string> strings = new List<string>(){"bob","ate","an", "apple"};
strings.IndexOf("bob");
strings.IndexOf("an");
strings.IndexOf("apple");
strings.IndexOf("banana");