title: C# Collection initialization syntax for use with custom matrix class?
body: <p>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</p>
  
  <pre><code>Matrix a = new Matrix(2,2){{1,2},{3,4}};
  </code></pre>
  
  <p>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</p>
  
  <pre><code>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 =&gt; m[rows, cols];
              set =&gt; m[rows, cols] = value;
          }       
  
          public Matrix(int rows, int cols)
          {
              m = new double[rows, cols];
          }
      ...
      }
  </code></pre>
  
  <p>so, how would I go about doing the Add() method anyway?</p>