2015-04-23 48 views

回答

0

您需要有一個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例如,你可以讓showstatic

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 
} 
0

改變類的訪問修飾符公共或受保護的。

相關問題