

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to find the index of an element in a List
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
- Related Questions & Answers
- How to find what is the index of an element in a list in Python?
- How to find the index of given element of a Java List?
- Write a program to find the index of particular element in an array in javascript?
- How to find the index of an element in a vector in R?
- How do you get the index of an element in a list in Java?
- How to find the index of an object available in a list in Python?
- Python program to compute the power by Index element in List
- How to find the last occurrence of an element in a Java List?
- Program to find H-Index from a list of citations in C++
- Python Program to find the cube of each list element
- How to find the index of an item in a C# list in a single step?
- How to remove an element from a list by index in Python?
- How to find the index of an item given a list containing it in Python?
- Write a Golang program to find the frequency of an element in an array
- Program to find a list of product of all elements except the current index in Python
Advertisements