public class TouchableArea {
public Rect rect;
public Rect Rect{
get{return rect;}
set{rect = value;}
}
}
上記は私のクラスです。 Rect
は構造体であり、新しい値を設定するための関数Set
を持っています。プロパティを使って新しい値をrectに設定すると、何も起こりませんが、rectを直接使うとすべてが問題ありません。C#でプロパティから関数を呼び出せませんか?
TouchableArea t = new TouchableArea();
t.Rect.Set(newValue);//Through property, nothing happens
t.rect.Set(newValue);//Directly access, it works.
これは、プロパティを介して関数を呼び出すことは不正ですか?
参照:[変更可能な構造体はなぜ悪いのですか?](http://stackoverflow.com/questions/441309/why-are-mutable-structs-evil) – Ani
@Ani私はあなたが説明する必要があると思う – Baz1nga