Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. AddRange and RemoveRange inconsistencies

AddRange and RemoveRange inconsistencies

Scheduled Pinned Locked Moved .NET (Core and Framework)
cssdatabasevisual-studiocomquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    n podbielski
    wrote on last edited by
    #1

    Method AddRange takes IEnumerable collection it makes perfect sense since we want to add second collection to our first list. http://msdn.microsoft.com/en-us/library/z883w3dc%28v=vs.80%29.aspx[^] But when you want to remove some items from collection that are in second collection (scenarion 2 grids with items and one bucket of possibilities for them, and cannot have shared items, available grid and items selected by user grid), there is RemoveRange method, right? No this method takes 2 ints http://msdn.microsoft.com/en-US/library/y33yd2b5%28v=vs.80%29.aspx[^]. Odd. RemoveAll? This for instance takes predicate for items. http://msdn.microsoft.com/en-US/library/wdka673a%28v=vs.80%29.aspx[^]So why this is called RemoveAll? Since it's takes predicate as Where takes why this is not called RemoveWhere? From RemoveAll I would expect behavior like Clear method, but we don't need another one like that. Method Remove takes item and removes it from collection. So why there is not method that takes range? How many times you have to remove items by range of indexes from collection (RemoveRange)? It would have to be ordered list to make it usable at some point since when you get index and number of items to remove you have to order and iterate it and since you do that why not just remove those items already? So in the end I using AddRange and extension method RemoveRange that iterates and calls Remove on second collection. Am I allone on that?

    No more Mister Nice Guy... >: |

    L 1 Reply Last reply
    0
    • N n podbielski

      Method AddRange takes IEnumerable collection it makes perfect sense since we want to add second collection to our first list. http://msdn.microsoft.com/en-us/library/z883w3dc%28v=vs.80%29.aspx[^] But when you want to remove some items from collection that are in second collection (scenarion 2 grids with items and one bucket of possibilities for them, and cannot have shared items, available grid and items selected by user grid), there is RemoveRange method, right? No this method takes 2 ints http://msdn.microsoft.com/en-US/library/y33yd2b5%28v=vs.80%29.aspx[^]. Odd. RemoveAll? This for instance takes predicate for items. http://msdn.microsoft.com/en-US/library/wdka673a%28v=vs.80%29.aspx[^]So why this is called RemoveAll? Since it's takes predicate as Where takes why this is not called RemoveWhere? From RemoveAll I would expect behavior like Clear method, but we don't need another one like that. Method Remove takes item and removes it from collection. So why there is not method that takes range? How many times you have to remove items by range of indexes from collection (RemoveRange)? It would have to be ordered list to make it usable at some point since when you get index and number of items to remove you have to order and iterate it and since you do that why not just remove those items already? So in the end I using AddRange and extension method RemoveRange that iterates and calls Remove on second collection. Am I allone on that?

      No more Mister Nice Guy... >: |

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      n.podbielski wrote:

      Am I allone on that?

      Yes/no. With a large framework, there's bound to be some inconsistencies. Yes, it would help if we could deduce the name of the method we want to call, based on fixed patterns. No, I don't see it happening. As for the range, I'd expect two ints, as the indexes are a good way to define a range. That's a bit harder to do with an IEnumerable. RemoveWhere(thisconditionistrue) or RemoveAll(thisconditionistrue); yes, your version sounds better, but it'll be hard to convince MS to change it. Especially after it's being used already in a lot of sourcecode.

      Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups