Answers for "c# get index of item in list"

C#
1

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",
      };

      // finding index
      int index = myList.FindIndex(a => a.Contains("Tennis"));

      // displaying index
      Console.WriteLine("List Item Tennis Found at index: " + index);
   }
}
Posted by: Guest on January-28-2021
1

Get Index position of an element in a list in c#

int index = myList.FindIndex(a => a.Prop == oProp);
Posted by: Guest on April-25-2021
5

c# get index of item in list

Array.IndexOf(arrName, searchingFor)
Posted by: Guest on June-12-2020
0

index of item in list C#

List<string> strings = new List<string>(){"bob","ate","an", "apple"};
strings.IndexOf("bob");
//returns 0 
strings.IndexOf("an");
//returns 2
strings.IndexOf("apple");
//returns 3
strings.IndexOf("banana");
//returns -1
//Because banana is not in the list, IndexOf() returns -1
Posted by: Guest on May-19-2021

Code answers related to "c# get index of item in list"

C# Answers by Framework

Browse Popular Code Answers by Language