Created
September 15, 2023 08:22
-
-
Save ufcpp/25305c2a9a9fbc0ca92a61fd67ca0c11 to your computer and use it in GitHub Desktop.
プライマリコンストラクター引数のキャプチャ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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