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#
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());
}
}