Monday, February 12, 2018

Get the index of an item in a list in C#

int index = myList.FindIndex(a => a.Prop == oProp);
If you don't want to use LINQ, then:
int index;
for (int i = 0; i < myList.Count; i++)
{
    if (myList[i].Prop == oProp)
    {
       index = i;
       break;
    }
}

No comments :

Post a Comment