diff --git a/AioNet.DataStructures/Matrix.cs b/AioNet.DataStructures/Matrix.cs index 77cb5f4..3a283dc 100644 --- a/AioNet.DataStructures/Matrix.cs +++ b/AioNet.DataStructures/Matrix.cs @@ -1,6 +1,39 @@ -namespace AioNet.DataStructures; +using System; -public static class Matrix +namespace AioNet.DataStructures { - + public static class Matrix + { + public static int NumberOfRows(this T[,] source) + { + return source.GetLength(0); + } + + public static int NumberOfColumns(this T[,] source) + { + return source.GetLength(1); + } + + public static T[][] ToJaggedArray(this T[,] source) + { + int rows = source.NumberOfRows(); + int columns = source.NumberOfColumns(); + + T[][] jaggedArray = new T[rows][]; + + for (int row = 0; row < rows; row++) + { + T[] currentRow = new T[columns]; + + for (int column = 0; column < columns; column++) + { + currentRow[column] = source[row, column]; + } + + jaggedArray[row] = currentRow; + } + + return jaggedArray; + } + } }