Exists Method Implementation for Multidimensional Array in C# To determine whether the specified array contains specific element or not, Array.Exists can be used if the given array is one dimensional. I am attempting to implement Exists method for multidimensional array cases.
The experimental implementation
static class MDArrayHelpers
{
    public static bool Exists&lt;T&gt;(Array array, Predicate&lt;T&gt; match)
        where T : unmanaged
    {
        if (ReferenceEquals(array, null))
        {
            throw new ArgumentNullException(nameof(array));
        }

        Type elementType = array.GetType().GetElementType();
        if (!elementType.Equals(typeof(T)))
        {
            throw new System.InvalidOperationException();
        }

        foreach (var element in array)
        {
            if (match((T)element))
            {
                return true;
            }
        }
        return false;
    }
}

Test cases
Predicate&lt;int&gt; isOne = delegate (int number) { return number == 1; };
Predicate&lt;int&gt; isFour = delegate (int number) { return number == 4; };


Console.WriteLine(&quot;One dimensional case&quot;);
int[] array1 = new int[] { 1, 2, 3 };
Console.WriteLine($&quot;Is one existed in {nameof(array1)}: {Array.Exists(array1, isOne)}&quot;);
Console.WriteLine($&quot;Is four existed in {nameof(array1)}: {Array.Exists(array1, isFour)}&quot;);
Console.WriteLine(&quot;&quot;);

Console.WriteLine(&quot;Two dimensional case&quot;);
int[,] array2 = { { 0, 1 }, { 2, 3 } };
Console.WriteLine($&quot;Is one existed in {nameof(array2)}: {MDArrayHelpers.Exists(array2, isOne)}&quot;);
Console.WriteLine($&quot;Is four existed in {nameof(array2)}: {MDArrayHelpers.Exists(array2, isFour)}&quot;);
Console.WriteLine(&quot;&quot;);

Console.WriteLine(&quot;Three dimensional case&quot;);
int[,,] array3 = { { { 0, 1 }, { 2, 3 } }, { { 0, 1 }, { 2, 3 } } };
Console.WriteLine($&quot;Is one existed in {nameof(array3)}: {MDArrayHelpers.Exists(array3, isOne)}&quot;);
Console.WriteLine($&quot;Is four existed in {nameof(array3)}: {MDArrayHelpers.Exists(array3, isFour)}&quot;);
Console.WriteLine(&quot;&quot;);

Console.WriteLine(&quot;Four dimensional case&quot;);
int[,,,] array4 = { { { { 0, 1 }, { 2, 3 } }, { { 0, 1 }, { 2, 3 } } }, { { { 0, 1 }, { 2, 3 } }, { { 0, 1 }, { 2, 3 } } } };
Console.WriteLine($&quot;Is one existed in {nameof(array4)}: {MDArrayHelpers.Exists(array4, isOne)}&quot;);
Console.WriteLine($&quot;Is four existed in {nameof(array4)}: {MDArrayHelpers.Exists(array4, isFour)}&quot;);

The output of the test code above:
One dimensional case
Is one existed in array1: True
Is four existed in array1: False

Two dimensional case
Is one existed in array2: True
Is four existed in array2: False

Three dimensional case
Is one existed in array3: True
Is four existed in array3: False

Four dimensional case
Is one existed in array4: True
Is four existed in array4: False

If there is any possible improvement, please let me know.
You can simply use the LINQ Enumerable.Any extension Method.
bool result = array4.Cast&lt;int&gt;().Any(x =&gt; x == 1);

This works for any collection implementing IEnumerable&lt;T&gt; and also for enumerations created algorithmically by C# Iterators.
According the the C# Programming Guide (Arrays):

Array types are reference types derived from the abstract base type Array. Since this type implements IEnumerable and IEnumerable&lt;T&gt;, you can use foreach iteration on all arrays in C#.

This statement is, however, misleading, since we need to cast the array here. Obviously, we only have the access to the non-generic interface IEnumerable.
LINQ Extension methods found in the Enumerable Class apply to IEnumerable&lt;T&gt; or IEnumerable.