0
public readonly int items = 3;
private System.Windows.Forms.TextBox[,] statsBonus = new System.Windows.Forms.TextBox[6, items];

It's giving me this error on the "items" variable. How do I make it so that I can use a variable called "items" instead of having to write 3 in every field that uses the number 3?

If I want to edit this on the code, I don't want to have to change the number 3 to something else manually. I want to use a variable so all I have to do is just change the variable to change everything.

puretppc
  • 3,146
  • 7
  • 35
  • 63

3 Answers3

3

Instead of using readonly use const

EDIT:

For a more discussed difference between the two, check out this SO answer

Community
  • 1
  • 1
Matt
  • 2,646
  • 1
  • 16
  • 24
2

You must use

const int items = 3;
Omer
  • 5,464
  • 12
  • 58
  • 73
1

One option

Move it to the constructor:

public ClassName()
{
  statsBonus = new System.Windows.Forms.TextBox[6, items];
}

Better option

Make items a const.

poy
  • 9,640
  • 9
  • 43
  • 71