Find element in List<> that contains a value
You can use the Where
to filter and Select
to get the desired value.
MyList.Where(i=>i.name == yourName).Select(j=>j.value);
Either use LINQ:
var value = MyList.First(item => item.name == "foo").value;
(This will just find the first match, of course. There are lots of options around this.)
Or use Find
instead of FindIndex
:
var value = MyList.Find(item => item.name == "foo").value;
I'd strongly suggest using LINQ though - it's a much more idiomatic approach these days.
(I'd also suggest following the .NET naming conventions.)