I'm creating a custom matrix class that only has a single 2D array to hold everything (I know that a 1D array is faster and better, but that's not the point of this implementation) the thing is, I'd like to have a constructor, and be able to do something like
Matrix a = new Matrix(2,2){{1,2},{3,4}};
and have it all work out. I've run into the "'Matrix' does not contain a definition for 'Add' and no extension method 'Add' etc." but after looking around, I've yet to be able to find robust enough info on how to define the Add() method in order to make it work. Here's the code I have so far
public class Matrix : IEnumerable
{
/* What we know abuot matricies
* - matricies are defined by rows, cols
* - addition is element-wise
*/
public IEnumerator GetEnumerator()
{
yield return m;
}
private void Add(double a)
{
// what exactly should go here anyway?
}
private double[,] m;
public double this[int rows, int cols]
{
get => m[rows, cols];
set => m[rows, cols] = value;
}
public Matrix(int rows, int cols)
{
m = new double[rows, cols];
}
...
}
so, how would I go about doing the Add() method anyway?