Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach (MyObject myObject in MyListOfMyObjects)
- {
- if (condition) MyListOfMyObjects.Remove(myObject);
- }
- foreach (MyObject myObject in new List<MyObject>(MyListOfMyObjects))
- {
- if (condition) MyListOfMyObjects.Remove(myObject);
- }
- List myFilteredList = new List();
- foreach (MyObject myObject in myListOfMyObjects)
- {
- if (!condition) myFilteredList.Add(myObject);
- }
- var myFilteredList = from myObject in myListOfMyObjects
- where !condition
- select myObject;
- void RemoveAll(object condition)
- {
- bool found = false;
- foreach(object thisObject in objects)
- {
- if (condition)
- {
- objects.Remove(thisObject);
- found = true;
- break; //exit loop
- }
- }
- // Call again recursively
- if (found) RemoveAll(condition);
- }
Add Comment
Please, Sign In to add comment