...由于其保护级别为c#/ asp.net而无法访问

hol*_*ard 4 c# asp.net protection class

我有一个单独的类的应用程序,我在代码隐藏文件(在Page_Load中)实例化.在课堂上有一些方法,我希望能够从幕后文件中的代码调用,但由于某种原因它不工作(SecretNumber.MakeGuess(INT)是人迹罕至,由于它的保护级别).这个班级和方法是公开的,那么原因是什么呢?

// Default.asx.cs

...

protected void btnCheckNr_Click(object sender, EventArgs e)
{
    if (!Page.IsValid){
        return;
    }

    else{
        var guessedNr = int.Parse(inputBox.Text);
        var result = SecretNumber.MakeGuess(guessedNr); <- inaccessible due to...
    }
}
Run Code Online (Sandbox Code Playgroud)

// SecretNumber.cs

public class SecretNumber {

    enum Outcome {
        Indefinite,
        Low,
        High,
        Correct,
        NoMoreGuesses,
        PreviousGuess
    };

    // Other code goes here...

    public Outcome MakeGuess(int guess) {
        // Other code here
    }
}
Run Code Online (Sandbox Code Playgroud)

Joh*_*aft 5

这是因为您的结果枚举是私人的.同样在你的代码中,MakeGuess需要被标记为静态,以便按照你编写的方式使用.