Hi, I am new here and was looking for a little help. I am writing a console application to play yahtzee. I have a die class, a dice class (with a dice array composed of five die), and my yahtzee class that has my Main method. My die has a private bool variable held. I created a get and set for held. I created a switch to allow the user to hold certian die:

public class Die
	{
		private int count; //value of die
		private bool held; //false if not held, true if held
		public Die()
		{
			count = 0; //pre-roll
			held = false; //dice is not being held to start
		}
		public int Count
		{
			get
			{
				return count; //gives the value of the die
			}
		}
		public bool Held
			//assign whether the dice is held or not
		{
			get
			{
				return held;
			}
			set
			{
				held = value; 
			}
		}
 
...
 
public void UserInputAfterRoll(Dice dice, Yahtzee yahtzee, ScoreSheet scoreSheet01)
		{
			Console.Write("What would you like to do?");
			string userChoice = Console.ReadLine();
			switch (userChoice)
			{
				case "Hold Die #1":
					dice.Dice01[0].Held = true;
					Console.WriteLine("Dice #1 has been held.");
					goto NextChoice;

The problem is that the held variable is not changing to true. I set a breakpoint on the code and a watch on held. Before my code reached the set for Held it said identifer 'held' out of scope, then it seems to set held to true, but then it says identifier held is out of scope again. Can anyone offer suggestions as to why the dice are not holding. Is it because of the out of scope error? or something else? Sorry if I did not provide enough details of my code. If you would like to see all of the code just let me know.

PS. The only other thing I can think of is after case "Hold Die #1" i have a goto statement that returns to the switch so the user can hold another die, would this screw with it at all?

1) if all you are going to do with the get and set is

public bool Held
//assign whether the dice is held or not
{
get
{
return held;
}
set
{
held = value;
}
}

you might as well make it a public variable

2) why in the world are you using goto?

1) if all you are going to do with the get and set is
you might as well make it a public variable
QUOTE]

actually that property is the only thing which he did right.
sorry but everything else in your code is flawed

i dont see an indexer in your class so i dont know how your doing that dice array.

NEVER use goto. you put your code in a function and call the function

and in your case never expect the user to type exactly what you want.
before you push it thru your case statment convert it to lowercase and take out that # or look "hold die" then look after that for the first number

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.