Set a list and add elements −
List<int> val = new List<int>(); // integer elements val.Add(35); val.Add(55); val.Add(68);
Let’s say now we need to find the index of element 68. For that, use the IndexOf() method −
int index = val.IndexOf(68);
Here is the complete code −
Example
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
List<int> val = new List<int>();
// integer elements
val.Add(35);
val.Add(55);
val.Add(68);
// finding the index of element 68
int index = val.IndexOf(68);
Console.WriteLine(index);
}
}Output
2