ForEach Methods Implementation for Multidimensional Array in C# I am working with System.Array and I found that the input parameter of ForEach method public static void ForEach&lt;T&gt;(T[] array, Action&lt;T&gt; action); is specified on one dimensional array case. I am trying to generalize this to multidimensional array.
The experimental implementation
Here's the experimental implementation of generalized ForEach method.
class ArrayHelpers
{
    public static void ForEach&lt;T&gt;(Array array, in Action&lt;T&gt; action)
        where T : unmanaged
    {
        if (ReferenceEquals(array, null))
        {
            throw new ArgumentNullException(nameof(array));
        }

        if (ReferenceEquals(action, null))
        {
            throw new ArgumentNullException(nameof(action));
        }

        foreach (T item in array)
        {
            action.Invoke(item);
        }
        return;
    }
}

Test cases
The Test cases for one dimensional case, two dimensional case and three dimensional case are as below.
//    One dimensional case
Console.WriteLine(&quot;One dimensional case&quot;);
int[] test = new int[] { 1, 2, 3, 4 };
ArrayHelpers.ForEach&lt;int&gt;(test, ShowSquares);

//    two dimensional case
Console.WriteLine(&quot;Two dimensional case&quot;);
int[,] test2 = { { 0, 1 }, { 2, 3 } };
ArrayHelpers.ForEach&lt;int&gt;(test2, ShowSquares);

//    three dimensional case
Console.WriteLine(&quot;Three dimensional case&quot;);
int[,,] test3 = { { { 0, 1 }, { 2, 3 } }, { { 0, 1 }, { 2, 3 } } };
ArrayHelpers.ForEach&lt;int&gt;(test3, ShowSquares);

/// &lt;summary&gt;
/// Reference: https://docs.microsoft.com/en-us/dotnet/api/system.array.foreach?view=net-5.0
/// &lt;/summary&gt;
/// &lt;param name=&quot;val&quot;&gt;The input value for displaying and calculating square result&lt;/param&gt;
private static void ShowSquares(int val)
{
    Console.WriteLine(&quot;{0:d} squared = {1:d}&quot;, val, val * val);
}

The output of the above tests:
One dimensional case
1 squared = 1
2 squared = 4
3 squared = 9
4 squared = 16
Two dimensional case
0 squared = 0
1 squared = 1
2 squared = 4
3 squared = 9
Three dimensional case
0 squared = 0
1 squared = 1
2 squared = 4
3 squared = 9
0 squared = 0
1 squared = 1
2 squared = 4
3 squared = 9

I am wondering the things about the potential drawback or risks of this implementation.
All suggestions are welcome.
The solution is fine as it easy as it could be but there's a better way to make the access to it - extension method.
public static class ArrayHelpers
{
    public static void ForEach&lt;T&gt;(this Array array, in Action&lt;T&gt; action)
    {
        if (ReferenceEquals(array, null))
        {
            throw new ArgumentNullException(nameof(array));
        }

        if (ReferenceEquals(action, null))
        {
            throw new ArgumentNullException(nameof(action));
        }

        foreach (T item in array)
        {
            action.Invoke(item);
        }
        return;
    }
}

Then the test cases can look like this
Console.WriteLine(&quot;One dimensional case&quot;);
int[] test = new int[] { 1, 2, 3, 4 };
test.ForEach&lt;int&gt;(ShowSquares);

Console.WriteLine(&quot;Two dimensional case&quot;);
int[,] test2 = { { 0, 1 }, { 2, 3 } };
test2.ForEach&lt;int&gt;(ShowSquares);

Console.WriteLine(&quot;Three dimensional case&quot;);
int[,,] test3 = { { { 0, 1 }, { 2, 3 } }, { { 0, 1 }, { 2, 3 } } };
test3.ForEach&lt;int&gt;(ShowSquares);