I have an application with a separate class, that i'm instantiating in the code behind-file (in Page_Load). In the class there's some methods that I want to be able to call from the code behind-file, but by some reason it doesn't work (SecretNumber.MakeGuess(int) is inaccessible due to it's protection level). The class as well as the methods are public so what can be the reason?
// 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...
}
}
// 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
}
}
It is because your Outcome enumeration is private. Also in the code you have, MakeGuess needs to be marked as static to be used the way you have it written.