-2
我能夠訪問show()
方法在另一類嘗試訪問方法中的嵌套類(兩者都在同一個類中)。
我能夠訪問show()
方法在另一類嘗試訪問方法中的嵌套類(兩者都在同一個類中)。
您需要有一個heai
的實例才能訪問show
。
像這樣:
void display()
{
var h = new heai();
store();
Console.WriteLine(num + name);
h.show(); // here you are calling show on the instance of heai
}
順便說一句:這有沒有關係嵌套類。對於任何其他班級來說都是一樣的。
如果你不希望有一個heai
例如,你可以讓show
static
:
private class heai
{
public static void show()
{
Console.WriteLine("hai");
}
}
然後調用它像這樣:
void display()
{
store();
Console.WriteLine(num + name);
heai.show(); // note: we are not accessing an instance of heai here, but the class itself
}
改變類的訪問修飾符公共或受保護的。
不要把紅旗質疑請如果你認爲它值得紅旗請讓我知道如何提出好問題 –