是否可以在 C# 中扩展数组? [英] Is it possible to extend arrays in C#?
本文介绍了是否可以在 C# 中扩展数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我习惯于向 IEnumerable 等外部类添加方法.但是我们可以在 C# 中扩展数组吗?
I'm used to add methods to external classes like IEnumerable. But can we extend Arrays in C#?
我打算向数组添加一个方法,即使它是多维的,也可以将其转换为 IEnumerable.
I am planning to add a method to arrays that converts it to a IEnumerable even if it is multidimensional.
推荐答案
static class Extension
{
public static string Extend(this Array array)
{
return "Yes, you can";
}
}
class Program
{
static void Main(string[] args)
{
int[,,,] multiDimArray = new int[10,10,10,10];
Console.WriteLine(multiDimArray.Extend());
}
}
这篇关于是否可以在 C# 中扩展数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文