Why doesn't IList support AddRange

后端 未结 2 1024
余生分开走
余生分开走 2020-12-09 00:54

List.AddRange() exists, but IList.AddRange() doesn\'t.
This strikes me as odd. What\'s the reason behind this?

2条回答
  •  隐瞒了意图╮
    2020-12-09 00:55

    Because an interface shoud be easy to implement and not contain "everything but the kitchen". If you add AddRange you should then add InsertRange and RemoveRange (for symmetry). A better question would be why there aren't extension methods for the IList interface similar to the IEnumerable interface. (extension methods for in-place Sort, BinarySearch, ... would be useful)

提交回复
热议问题