由网友(被伱殖民的心脏)分享简介:我用来添加方法外部类,如IEnumerable的。但是,我们能够扩展阵列在C#?我打算一个方法添加到阵列将其转换为IEnumerable的,即使它是多维的。不相关的http://stackoverflow.com/questions/628427/how-to-extend-arrays-in-c解决方案 静态类扩...![实践篇 实时影子](https://p.xsw88.cn/allimgs/daicuo/20230903/919.png)
我用来添加方法外部类,如IEnumerable的。但是,我们能够扩展阵列在C#?
我打算一个方法添加到阵列将其转换为IEnumerable的,即使它是多维的。
不相关的http://stackoverflow.com/questions/628427/how-to-extend-arrays-in-c
解决方案 静态类扩展
{
公共静态字符串扩展(该阵列阵列)
{
返回是的,你可以;
}
}
类节目
{
静态无效的主要(字串[] args)
{
INT [,,,] multiDimArray =新INT [10,10,10,10]
Console.WriteLine(multiDimArray.Extend());
}
}
I'm used to add methods to external classes like IEnumerable. But can we extend Arrays in C#?
![实践篇 实时影子](https://p.xsw88.cn/allimgs/daicuo/20230903/919.png)
I am planning to add a method to arrays that converts it to a IEnumerable even if it is multidimensional.
Not related to http://stackoverflow.com/questions/628427/how-to-extend-arrays-in-c
解决方案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());
}
}
相关推荐
最新文章