public static QueriableMatrix <T> ToQueriableMatrix <T>(this IEnumerable <T> collection, int rows, int columns) { // reuse code like a baws :D var matrix = collection.ToMatrix(rows, columns); var queriableMatrix = new QueriableMatrix <T>(matrix); return(queriableMatrix); }
public static void Main() { var rng = new Random(); var normalMatrix = new int[3, 4]; var queriableMatrix = new QueriableMatrix <int>(normalMatrix) // wrap the matrix .Select(x => (rng.Next() % 20) + 51) // the adapter pattern allows the use of linq on matrices .OrderBy(x => x) // some LINQ operations just for the sake of showing off .Select(x => (char)x) .ToQueriableMatrix(4, 3) .Skip(2) .ToQueriableMatrix(2, 5); PrintMatrix(queriableMatrix.Value); Console.WriteLine("\nim kewl\n"); PrintMatrix(queriableMatrix.ToMatrix(5, 2)); }