我知道一个属性具有以下形式:
class MyClass
{
public int myProperty { get; set; }
}
这允许我这样做:
MyClass myClass = new MyClass();
myClass.myProperty = 5;
Console.WriteLine(myClass.myProperty); // 5
但是,我该怎么做才能使以下课程:
class MyOtherClass
{
public int[,] myProperty
{
get
{
// Code here.
}
set
{
// Code here.
}
}
}
行为如下:
/* Assume that myProperty has been initialized to the following matrix:
myProperty = 1 2 3
4 5 6
7 8 9
and that the access order is [row, column]. */
myOtherClass.myProperty[1, 2] = 0;
/* myProperty = 1 2 3
4 5 0
7 8 9 */
Console.WriteLine(myOtherClass.myProperty[2, 0]); // 7
提前致谢!