public class SecretNumber
{
//Construktor
public SecretNumber()
{
Initialize();
_previousGuesses = new List<int>();
}
//Constant
public const int MaxNumberOfGuesses = 7;
//Field
private int _number;
private List<int> _previousGuesses;
//Property
public bool CanMakeGuess
{
get;
}
public int Count
{
get;
}
public int? Number
{
public get;
}
//Lite oklart hur man ska göra när fälten är autoimplementerade
public Outcome Outcome1
{
get
{
return Outcome1;
}
private set
{
Outcome1 = value;
}
}
public ReadOnlyCollection<int> PreviousGuesses
{
get;
set;
}
//Methods
public void Initialize()
{
Random random = new Random();
_number = random.Next(1, 100);
_previousGuesses.Clear();
Outcome1 = Outcome.Indefinite;
}
private Outcome MakeGuess(int guess)
{
if (Number > 1 && Number < 100)
{
if (PreviousGuesses.Contains(guess))
{
return Outcome.PreviousGuess;
}
else if (PreviousGuesses.Count >= MaxNumberOfGuesses)
{
return Outcome.NoMoreGuesses;
}
if (Number == guess)
{
return Outcome.Correct;
}
else if (Number < guess)
{
return Outcome.High;
}
// else if (Number > guess)
// {
return Outcome.Low;
// }
}
else
{
throw new ArgumentOutOfRangeException("Måste vara inom intervallet 1-100");
}
}
//Enumerator
enum Outcome
{
Indefinite,
Low,
High,
Correct,
NoMoreGuesses,
PreviousGuess
}
}
I get the errormessage that my enum Secret number has lesses accessability than the property Outcome1, but I have no idea why.
The property is called Outcome1 because otherwise the names were mixed up in Visual Studio.
Your enum has
privatevisibility as you haven’t given it an explicit visibility, and it’s nested within yourSecretNumberclass.You can’t use a type as a parameter or return type of a member that’s exposed publicly1 when that type isn’t also public – otherwise the caller wouldn’t know what to do with it.
You can just make it public:
1 That’s not quite the same as “of a public member”. For example, a
public(non-overriding) method in aninternaltype can refer to other internal members as parameters – because the method could still only be called by another type which knew about the “containing”internaltype anyway.