remove item from list in for loop csharp

Code Example - remove item from list in for loop csharp

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

how to delete from a list csharp

                        
                                var resultList = new List<int>();
resultList.Add(1);
resultList.Add(2);
resultList.Add(3);

// Removes the number 1 from the index 0 in the list
resultlist.RemoveAt(0);

// Allows you to remove an Object from the list instead
var itemToRemove = resultlist.Single(r => r.Id == 2);
resultList.Remove(itemToRemove);
                            
                        
 

csharp remove item from list

                        
                                list.Remove("Example String"); // Remove by value
list.RemoveAt(3); // Remove at index
list.RemoveRange(6, 3); // Remove range (removes 3 items starting at 6th position in this example)
                            
                        
 

csharp remove from list in foreach

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

csharp best way to loop and remove

                        
                                for (int i = safePendingList.Count - 1; i >= 0; i--)
{
    // some code
    // safePendingList.RemoveAt(i);
}