I’m trying to figure out how to find the "next matching" object in a C# List<MyObject> where I have a starting index.
Meaning suppose I have the following list.
List<MyObject> myList = new List<MyObject>
{
new MyObject
{
isActive = true
},
new MyObject
{
isActive = false
},
new MyObject
{
isActive = true
},
}
And I want to do myList.Find(x => x.IsActive) /// where index is greater than 0??
>Solution :
There is a FindIndex method on Lists that accepts a starting index value and a predicate so you could do something like this:
var idx = myList.FindIndex(1, x => x.IsActive)