Generate a matrix of booleans from another one
You can make this function more generic so that you can use reuse it where necessary and with any type. Currently your code is doing three things:


Loop over the matrix.
Checking a condition.
Modifying the elements.


This can be separated and encapsulated. You first create a general-purpose extension that just loops over any matrix, checks the passed predicate and calls the action:

public static T[,] ForEach&lt;T&gt;(
    this T[,] m, 
    Func&lt;T, bool&gt; predicate, 
    Action&lt;T, int, int&gt; action
)
{
    for (int x = 0; x &lt; m.GetLength(0); x++)
        for (int y = 0; y &lt; m.GetLength(1); y++)
            if (predicate(m[x, y])) action(m[x, y], x, y);

    return m;
}




Example:

Assuming you have these two matrices

var m1 = new[,]
{
    { false, false, false, false },
    { false, true, false, true },
    { true, true, false, false },
    { false, false, true, true }
};

var m2 = new[,]
{
    { false, true, true, false },
    { false, true, false, true },
    { true, true, false, false },
    { false, false, false, false }
};


you call the new ForEach extension like this where you first filter the items with !m so that you get only those where m = false, then you update the second matrix at the coordinates [x, y] with the value m of the first matrix.

m1.ForEach(m =&gt; !m, (m, x, y) =&gt; m2[x, y] = m);