C# 可以扩展数组吗?
I'm used to add methods to external classes like IEnumerable. But can we extend Arrays in C#?
I am planning to add a method to arrays that converts it to a IEnumerable even if it is multidimensional.
Not related to How to extend arrays in C#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的。 要么通过扩展 Array 类(如前所述),要么通过扩展特定类型的数组甚至通用数组:
最后一个并不完全等同于扩展 Array ,因为它不适用于多维数组,因此它受到更多限制,我想这可能很有用。
Yes. Either through extending the
Array
class as already shown, or by extending a specific kind of array or even a generic array:The last one is not exactly equivalent to extending
Array
, as it wouldn't work for a multi-dimensional array, so it's a little more constrained, which could be useful, I suppose.我做到了!
I did it!