Skip to content

Instantly share code, notes, and snippets.

@yuchiki
Created May 8, 2019 10:08
Show Gist options
  • Save yuchiki/0b08375bcf2cea240b78586c86430d9b to your computer and use it in GitHub Desktop.
Save yuchiki/0b08375bcf2cea240b78586c86430d9b to your computer and use it in GitHub Desktop.
同クラスの他インスタンスのprivateフィールドにアクセスできる例
namespace fuga
{
class MyClass {
int value; //privateなフィールド
public int GetValue(MyClass mc) => mc.value; // 同クラス他インスタンスのprivateフィールドにアクセスできる!!
public MyClass(int v) => value = v;
}
class Program
{
static void Main(string[] args)
{
var class1 = new MyClass(1);
var class2 = new MyClass(2);
Console.WriteLine(class1.GetValue(class2));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment