Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. foreach(var item in items)
  2. {
  3. if (object.ReferenceEquals(item, data))
  4. {
  5. // something like this items.Remove(item); should happen here
  6. }
  7.  
  8. public IEnumerable<T> Remove<T>(IEnumerable<T> enumeration, T toRemove)
  9. {
  10. return enumeration.Except(new[] { toRemove });
  11. }
  12.  
  13. annoyingEnumeration = this.Remove(annoyingEnumeration, annoyingItem);
  14.  
  15. public IEnumerable Remove(IEnumerable enumeration, object toRemove)
  16. {
  17. foreach (var e in enumeration)
  18. {
  19. if (!object.ReferenceEquals(e, toRemove))
  20. {
  21. yield return e;
  22. }
  23. }
  24. }
  25.  
  26. public static class ExtensionMethods
  27. {
  28. public IEnumerable Without(this IEnumerable enumeration, object toLeaveOut)
  29. {
  30. foreach (var e in enumeration)
  31. {
  32. if (!object.ReferenceEquals(e, toLeaveOut))
  33. {
  34. yield return e;
  35. }
  36. }
  37. }
  38. }
  39.  
  40. annoyingEnumeration = annyingEnumeration.Without(annoyingItem);
  41.  
  42. var result = new List<object>();
  43. foreach(var item in items)
  44. {
  45. if (!object.ReferenceEquals(item, data))
  46. {
  47. result.Add(item);
  48. }
  49. }
  50.  
  51. var filtered = items.Where(i => !object.ReferenceEquals(i, data));
  52.  
  53. var custom = new ArrayList();
  54.  
  55. foreach(var item in items)
  56. {
  57. // invert the check
  58. if (!object.ReferenceEquals(item, data))
  59. {
  60. // add on the custom result
  61. custom.Add(item);
  62. }
  63. }
  64.  
  65. return custom;
  66.  
  67. public static System.Collections.IEnumerable Remove<T>(this System.Collections.IEnumerable collection, T data)
  68. {
  69. foreach (var item in collection)
  70. if (!object.ReferenceEquals(item, data))
  71. yield return item;
  72. }
  73.  
  74. collection = collection.Remove(data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement