プロパティには次の形式があることを知っています。
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
前もって感謝します!