Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find with starting index?

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??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading