/// <summary> /// This version maps receive a 1d array but treats it as a 2d array /// </summary> /// <typeparam name="T">The type of the collection</typeparam> /// <param name="array">The collection</param> /// <param name="function">The function that will be operated in each object of the collection</param> public static void Foreach2D <T>(T[] array, int size, Foreach2DExplicitDelegate <T> function) { for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { function(new Coordinate(x, y), ref array[x * size + y]); } } }
/// <summary> /// This method facilitates the process of 2d foreaches, /// it no only exposes the coordinates of the iterate object for further use but /// also exposes the object itself as a ref (allowing me to manipulate the object itself) /// things that a normal foreach would not allow /// </summary> /// <typeparam name="T">The type of the collection</typeparam> /// <param name="array">The collection</param> /// <param name="function">The function that will be operated in each object of the collection</param> public static void Foreach2D <T>(T[,] array, Foreach2DExplicitDelegate <T> function) { for (int y = 0; y < array.GetLength(1); y++) { for (int x = 0; x < array.GetLength(0); x++) { function(new Coordinate(x, y), ref array[x, y]); } } }