c# remove from list in foreach
myList.RemoveAll(x => x.SomeProp == "SomeValue");
c# remove from list in foreach
myList.RemoveAll(x => x.SomeProp == "SomeValue");
Remove elements from a list while iterating over it in C#
using System;
using System.Collections.Generic;
using System.Linq;
public class Example
{
public static void Main()
{
List<int> list = new List<int>(Enumerable.Range(1, 10));
foreach (int item in list.Reverse<int>())
{
list.Remove(item);
}
}
}
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);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us