Embedding an indexer in F #

I am trying to convert this C # code to F #:

double[,] matrix;

public Matrix(int rows, int cols)
    {
        this.matrix = new double[rows, cols];
    }

 public double this[int row, int col]
    {
        get
        {
            return this.matrix[row, col];
        }
        set
        {
            this.matrix[row, col] = value;
        }
    }

Basically my biggest problem is creating an indexer in F #. I could not find anything that I could apply in this situation anywhere on the Internet. I included a couple of other parts of the class in case the inclusion of an indexer in a matrix type is not obvious. So a good answer would include how to make a full three-part type here, plus everything you might need. Also, I know the type of matrix in Powerpack F #, however I am trying to learn F # by converting C # projects that I understand into F #.

Thanks in advance,

Bean

+5
source share
1 answer

F # " "; MSDN. F # - .

, , "Item". , :

member this.Item
  with get(x,y) = matrix.[(x,y)]
  and  set(x,y) value = matrix.[(x,y)] <- value

instance.[0,0]. - , "Item", instance.Something[0,0].

+11

All Articles