Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Created February 1, 2015 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ufcpp/43dfc2bb8188f7634f03 to your computer and use it in GitHub Desktop.
Save ufcpp/43dfc2bb8188f7634f03 to your computer and use it in GitHub Desktop.
immutable and readonly in C#
class A
{
public int X { get; set; }
}
class B
{
public readonly A A = new A();
}
class Program
{
static void Main()
{
var b = new B();
b.A = new A(); // エラー: A は readonly
b.A.X = 10; // OK : X は別に readonly じゃない
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment