I'm trying to get the contents of a StringBuilder to display in a WinForms textbox, but the window never appears when I try to compile the program. This is my first venture into WinForms and C# and I've only used the language for about a week and a half now, so this is probably a simple fix that I'm just not seeing.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
StringBuilder builder = new StringBuilder();
Random rand = new Random();
int[] builderList = new int[10000];
for (int i = 0; i < 10000; i++)
{
builderList[i] = rand.Next(1, 20000);
builder.Append(builderList[i].ToString() + " ");
}
// This is the line that seems to be the problem...
textBox1.Text = builder.ToString();
}
}
When I try to run the program and insert a breakpoint on that last line of code, I can see that the program seems to just hit that line continuously. Oddly enough, if I change that line to this:
textBox1.Text = "Hey, lol";
my program will run. I checked the debugger in Visual Studio and saw that the contents of 'builderList' are updated to random numbers and 'builder' looks like it's correctly storing the values in 'builderList' as a string like I want, so I'm kind of confused about what's going on here. I'd appreciate any help I can get on this one as it seems like it should be a relatively easy fix but I've been stumped on it so far and I haven't really found anything helpful in the MSDN documentation.
Thanks so much!