I have a boolean which is set to false when being declared,
public bool row1 = false;
However, when I run some code in order to set the boolean to true, it doesn’t seem to be wokring,
if (currentBox.BackColor == cardColour)
{
MessageBox.Show("Please Draw a Card.");
}
else if (currentBox.BackColor != cardColour)
{
row = true;
}
The above code is the method body of a method which is being called in a picturebox mouse click event method (using row1 in the parameters when calling the method). At its current state, it’s saying it’s false when it should be set to true.
Here is the code which is calling the method.
private void rowOne_MouseClick(object sender, MouseEventArgs e)
{
AllowTake(row1, currentCardPictureBox, Color.White, sender, e);
}
Thanks for any help.
You should pass the
rowparameter by ref:row1is a separate local variable and its value is not used outside the method.After
MakeTrueis called the value ofmyFlagdoesn’t change. Its value is used to initialize aflagargument inMakeTruemethod and that’s it. After that whatever you do toflagwon’t affect the value ofmyFlag.Now, if you do this:
you will get the desired (in your case) behavior:
flagwill be just an alias formyFlagvariable and whatever you assign to it will become the value ofmyFlag.Some links to read:
refandoutin C#.