Erix
Erix

Reputation: 69

How to get the List Index of a List Tuple element

I have created a List Tuple String int like this:

public static List<Tuple<string, int>> myGrid = new List<Tuple<string, int>>();

myGrid.Add(new Tuple<string, int>("Alpha", 159));

I have done so, because I need to work with index in my code.

How to get the List index of Tuple Item1 or Item2?

Upvotes: 1

Views: 436

Answers (1)

Waescher
Waescher

Reputation: 5737

var indexByItem1 = myGrid.FindIndex(0, t => t.Item1 == "Alpha");
var indexByItem2 = myGrid.FindIndex(0, t => t.Item2 == 159);

See this interactive fiddle.

Upvotes: 1

Related Questions