So, both ListBox.ObjectCollection
and ListView.ListViewItemCollection
implement the IList
class, which provides Add
and Remove
methods but no AddRange
, InsertRange
, or RemoveRange
. However, ListBox.ObjectCollection
and ListView.ListViewItemCollection
also provide an AddRange
method -- just no InsertRange
or RemoveRange
.
Look at the ArrayList
class, on the other hand, which on top of implementing IList
also provides AddRange
, InsertRange
, and RemoveRange
. The same difference exists between the generic forms of this class and interface, List<T>
(which has AddRange
, InsertRange
, and RemoveRange
) and IList<T>
(which only provides Add
and Remove
).
I can understand the IList
and IList<T>
interfaces not providing AddRange
, etc. -- it's just an interface; anything beyond the minimum requirements of Add
, Remove
, RemoveAt
, etc. is optional. But, given the usefulness of the *Range
methods for the ArrayList
and List<T>
classes, and considering how handy they'd be for ListBox
and ListView
controls, I wonder why they don't exist for these controls.
Does anyone know? Is there something about the internal implementation of InsertRange
and RemoveRange
that makes these methods somehow less efficient, more complicated, or otherwise less appropriate for ListBox.ObjectCollection
and ListView.ListViewItemCollection
than AddRange
?
To be clear: I'm not looking for speculation of the "Looks like someone at Microsoft got lazy" variety; rather, I'm wondering if anyone actually knows of a legitimate difference between AddRange
and InsertRange
/RemoveRange
that might explain the absence of these latter methods from ListBox.ObjectCollection
and ListView.ListViewItemCollection
.