kinnan

kinnan

  • NA
  • 1
  • 0

NEED HELP! Arrays Getter and Setter method?

Apr 23 2009 4:49 PM
Please see the code below i am having difficulty understanding it.
I am using operator overloading to add two matrix of same size.

public const int size = 3;
int[,] matrix =new int[size,size];

Question1:
//What does the below function do?
public int this[int x, int y]
{
get { return matrix[x, y]; }
set { matrix[x, y] = value; }
}
Question2:
//why can i not use the name(matrix) to get the values from the array e.g?

public int matrix[int x, int y] //getting error on this
{
get { return matrix[x, y]; }
set { matrix[x, y] = value; }
}

Question3:
If i comment the below code it gives me error
i.e "Cannot apply indexing with [] to an expression of type".........etc
//public int this[int x, int y]
// {
// get { return matrix[x, y]; }
// set { matrix[x, y] = value; }
// }

WAITING FOR REPLY?
THANK YOU?

Answers (1)