remove item from list in for loop c#

57

c# remove from list in foreach -

myList.RemoveAll(x => x.SomeProp == "SomeValue");

remove item from list in for loop c# -

var data=new List<string>(){"One","Two","Three"};
for(int i=data.Count - 1; i > -1; i--)
{
    if(data[i]=="One")
    {
        data.RemoveAt(i);
    }
}

Comments

Submit
0 Comments