mirror of
https://onedev.fprog.nl/AioNet
synced 2026-01-05 13:13:41 +01:00
Added some basic methods for matrices.
This commit is contained in:
parent
917c2b3059
commit
5774675fbd
|
|
@ -1,6 +1,39 @@
|
|||
namespace AioNet.DataStructures;
|
||||
using System;
|
||||
|
||||
public static class Matrix
|
||||
namespace AioNet.DataStructures
|
||||
{
|
||||
|
||||
public static class Matrix
|
||||
{
|
||||
public static int NumberOfRows<T>(this T[,] source)
|
||||
{
|
||||
return source.GetLength(0);
|
||||
}
|
||||
|
||||
public static int NumberOfColumns<T>(this T[,] source)
|
||||
{
|
||||
return source.GetLength(1);
|
||||
}
|
||||
|
||||
public static T[][] ToJaggedArray<T>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue