From 5774675fbdb67d3f7575edb99543d2655d4703b7 Mon Sep 17 00:00:00 2001 From: Filip Strajnar Date: Thu, 23 May 2024 20:37:44 +0200 Subject: [PATCH] Added some basic methods for matrices. --- AioNet.DataStructures/Matrix.cs | 39 ++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) 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; + } + } }