Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Created September 15, 2023 08:22
Show Gist options
  • Save ufcpp/25305c2a9a9fbc0ca92a61fd67ca0c11 to your computer and use it in GitHub Desktop.
Save ufcpp/25305c2a9a9fbc0ca92a61fd67ca0c11 to your computer and use it in GitHub Desktop.
プライマリコンストラクター引数のキャプチャ
class A(int x)
{
int _x = x; // これはキャプチャしない。
}
class B(int x)
{
public int X { get; } = x; // これもキャプチャしない。
}
class C(int x)
{
public int X => x; // キャプチャ発生。(まあこれはいい)
}
class D(int x)
{
public int X { get; } = x; // キャプチャ発生しない。X のバッキングフィールドできる。
public int Y => x; // キャプチャ発生。X のとは別に引数キャプチャ用フィールドできる。
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment