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.

Omer
  • 8,194
  • 13
  • 74
  • 92
puretppc
  • 3,232
  • 8
  • 38
  • 65

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,682
  • 1
  • 17
  • 24
2

You must use

const int items = 3;
Omer
  • 8,194
  • 13
  • 74
  • 92
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
  • 10,063
  • 9
  • 49
  • 74