game/Extensions/ArrayExtension.cs
/// <summary>
/// Map function over 2D array and return result.
/// </summary>
/// <param name="array">2D array, which will be used for inputs.</param>
/// <param name="function">Function, which should be mapped over array.</param>
/// <typeparam name="TIn">Type of array we've got.</typeparam>
/// <typeparam name="TOut">Type of outcome array.</typeparam>
/// <returns>Result of mapping given function over input array.</returns>
Map function over 2D array and return result.
Map function over 2D array and return result .
public static TOut[,] Map<TIn, TOut>(this TIn[,] array, Func<TIn, TOut> function)
        {
            var arrayOut = new TOut[array.GetLength(0), array.GetLength(1)];
            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 0; j < array.GetLength(1); j++)
                {
                    arrayOut[i, j] = function(array[i, j]);
                }
            }
            return arrayOut;
        }
public static TOut [ , ] Map < TIn , TOut > ( this TIn [ , ] array , Func < TIn , TOut > function ) { var arrayOut = new TOut [ array . GetLength ( 0 ) , array . GetLength ( 1 ) ] ; for ( int i = 0 ; i < array . GetLength ( 0 ) ; i ++ ) { for ( int j = 0 ; j < array . GetLength ( 1 ) ; j ++ ) { arrayOut [ i , j ] = function ( array [ i , j ] ) ; } } return arrayOut ; }
Map function over 2D array and return result.
Map function over 2D array and return result .
Result of mapping given function over input array.
Result of mapping given function over input array .
TIn[,]
this
function
Func<TIn, TOut>
Function, which should be mapped over array.
Function which should be mapped over array .
array
2D array, which will be used for inputs.
2D array which will be used for inputs .
typeparam
Type of array we've got.
Type of array we ' ve got .
typeparam
Type of outcome array.
Type of outcome array .