为什么 IList没有采用 IEnumerable的 Insert 方法?
我现在的情况是,我只想将字符串数组(类型为 String[])中的值附加到具有 IList
I'm in a situation where I just want to append values in string array (type String[]) to an object with IList<String>. A quick look-up on MSDN revealed that IList<T>'s Insert method only has a version which takes an index and an object T, and does not have a version which takes IEnumerable<T> instead of T. Does this mean that I have to write a loop over an input list to put values into the destination list? If that's the case, it seems very limiting and rather very unfriendly API design for me. Maybe, I'm missing something. What does C# experts do in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为接口通常是使其可用所需的最少功能,以减轻实现者的负担。 使用 C# 3.0,您可以将其添加为扩展方法:
等等;
IList
现在有AddRange
:Because an interface is generally the least functionality required to make it usable, to reduce the burden on the implementors. With C# 3.0 you can add this as an extension method:
et voila;
IList<T>
now hasAddRange
: