-
C#- Help with code
Hello, I just need some quick help here:
Code:
this.Controls[string.Format("S" + S)].Show();
Code:
this.Controls[string.Format("S" + S)].Visible = true;
None of these works. I have controls called S0-S10(LineShapes). The S variable is currently 0. I get a NullReferenceException error during runtime.
Note: tried it with a button aswell.
Edit: It's for a hangman game, S0-S10 are lines and a sphere.
Thanks, I hope it's just something easy.
-
Re: C#- Help with code
What exactly is the string.Format call for? There's no formatting going on. If you were to use string.Format it would look like this:
Code:
this.Controls[string.Format("S{0}", S)].Show();
but that's pointless with so simple a string, so just do this:
Code:
this.Controls["S" + S].Show();
-
Re: C#- Help with code