Answers for "list c# find index"

C#
4

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
1

get index c#

int index = Array.IndexOf(arr,item);
Posted by: Guest on August-17-2021
0

c# find all indexes

public static int[] FindAllIndexOf<T>(this T[] array, Predicate<T> filter)
        {
  			// Note: If select does not find a match returns index as "-1"
            int[] indexes = array.Select((elementInArray, index) => filter(elementInArray) ? index : -1)
                                 .Where(index => index != -1).ToArray();

            return indexes;
        }
Posted by: Guest on June-17-2021
0

get index c#

int index = myList.FindIndex(a => a.Prop == oProp);
Posted by: Guest on March-27-2022

C# Answers by Framework

Browse Popular Code Answers by Language