16/05/15 10:54:19.95 jtZJEPOB.net
>>326
C#の場合、classでもstructでも
struct Foo {
public int A { get; set; }
}
としていれば、
Foo foo = new Foo();
foo.A = 100;
と書くことは可能。(当然public int A;でも可能)
color構造体の場合、
struct Color {
public byte A { get { ・・・ } }
}
という感じでgetterしか定義していないから、
Aは書き換えられない。(classの場合も同様)
こういうのをImmutableっていうかな。
(stringクラスもImmutableなので、中の文字列を書き換えられない)
※ただし、List<Foo> list = new List(); (略) list[0].A = 100;
は、Fooがclassなら可、structだとFooのコピーになるのでコンパイルエラー