WebAug 5, 2011 · C# IEnumerable allAgedTwenty = myList.Where ( x => return x.Age == 20; ); IEnumerable indices = allAgedTwenty.Select ( x => myList.IndexOf (x) ); The first case will get you only one int and the second case will leave you with a list of ints. Best Regards, —MRB Posted 5-Aug-11 1:27am Manfred Rudolf Bihy WebJan 20, 2024 · C# List class provides methods and properties to create a list of objects (types). For example, the IndexOf method returns the first index of an item if found in …
c# - How can I get the index of an item in a list in a single …
WebMay 27, 2024 · You definitely don't want to use an index to remove items as any index you could get would be indexing the input list as filtered by the Where which effectively creates a new sequence: If the input has ten items, and the last three are the ones you want, the index post Where would be 0 to 2 which doesn't reference any of them! WebThe List is searched forward starting at index and ending at the last element. This method determines equality using the default equality comparer EqualityComparer.Default for T, the type of values in the list. This method performs a linear search; therefore, this method is an O ( n) operation, where n is the number of … calla lily care potted outdoors
C# Gets or Sets the element at the specified index in the List
WebFeb 26, 2024 · List in C# is a collection of strongly typed objects. These objects can be easily accessed using their respective index. Index calling gives the flexibility to sort, search, and modify lists if required. In simple, List in C# is the generic version of the ArrayList. This ArrayList comes under System.Collection.Generic namespace. WebJun 22, 2024 · To get the index of an item in a single line, use the FindIndex () and Contains () method. int index = myList.FindIndex (a => a.Contains ("Tennis")); Above, … WebFeb 24, 2012 · I'm not sure I understand completely, but it sounds like you could resolve this be creating an indexer on class B to return the item you want: public object this[int index] { get { return list[index]; } } change 'object' to whatever your class type actually is. You can then access the items as if class B was an array: object item = classB[5]; coated with zinc to prevent rust