Search code examples
c#stringlistfor-loopxna

Adding strings to a list via for loop xna


So, I need 300 strings (1, 2, 3, 4, 5, etc, etc) And I've decided to use a for loop to add them to my list, but it keeps giving me errors no matter what I try and I'm very confused right now. This is what I currently have:

 int stringcount = 0;
 List<string> ButtonStrings;
 ButtonStrings = new List<string>();
 for (int i = 0; i < 299; i++)
        {
            stringcount += 1;
            ButtonStrings.Add(stringcount.ToString);
        }

Any and all help is greatly appreciated, thank you for taking the time to read this.


Solution

  • Instead of having stringcount.ToString, which is a method group, you need to call this method by adding parenthesis (). Change

    ButtonStrings.Add(stringcount.ToString);
    

    to

    ButtonStrings.Add(stringcount.ToString());