Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach(var item in items)
- {
- if (object.ReferenceEquals(item, data))
- {
- // something like this items.Remove(item); should happen here
- }
- public IEnumerable<T> Remove<T>(IEnumerable<T> enumeration, T toRemove)
- {
- return enumeration.Except(new[] { toRemove });
- }
- annoyingEnumeration = this.Remove(annoyingEnumeration, annoyingItem);
- public IEnumerable Remove(IEnumerable enumeration, object toRemove)
- {
- foreach (var e in enumeration)
- {
- if (!object.ReferenceEquals(e, toRemove))
- {
- yield return e;
- }
- }
- }
- public static class ExtensionMethods
- {
- public IEnumerable Without(this IEnumerable enumeration, object toLeaveOut)
- {
- foreach (var e in enumeration)
- {
- if (!object.ReferenceEquals(e, toLeaveOut))
- {
- yield return e;
- }
- }
- }
- }
- annoyingEnumeration = annyingEnumeration.Without(annoyingItem);
- var result = new List<object>();
- foreach(var item in items)
- {
- if (!object.ReferenceEquals(item, data))
- {
- result.Add(item);
- }
- }
- var filtered = items.Where(i => !object.ReferenceEquals(i, data));
- var custom = new ArrayList();
- foreach(var item in items)
- {
- // invert the check
- if (!object.ReferenceEquals(item, data))
- {
- // add on the custom result
- custom.Add(item);
- }
- }
- return custom;
- public static System.Collections.IEnumerable Remove<T>(this System.Collections.IEnumerable collection, T data)
- {
- foreach (var item in collection)
- if (!object.ReferenceEquals(item, data))
- yield return item;
- }
- collection = collection.Remove(data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement