OK, let's point out all bugs:
private void btnDeal_Click(object sender, EventArgs e)
{
int[] numbers = { 9, 8, 7, 6 };
for (int i = 0; i != numbers.Length; i++)
{
int num = numbers[i];
txtNorth.Text = num.ToString();
i++;
}
}
Fixed:
static readonly int[] numbers = { 9, 8, 7, 6 };
static string delimiter = " ";
btnDeal.Click += (sender, eventArgs) => {
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach(int number in numbers) {
sb.Append(number.ToString());
sb.Append(delimiter);
}
txtNorth.Text = sb.ToString().Trim();
}
This is a variant of delegate method for C# v.2 where lambda syntax was not yet introduced:
btnDeal.Click += delegate(object sender, System.EventArgs eventArgs) {
}
</pre>
Some explanation about Microsoft naming conventions: Yes, this name was generated by Microsoft, by Designer. So what? Who told that you're supposed to leave these names as is? You should renamed
all auto-generated names into semantic names. The refactoring engine makes it easy. Do it, if you want to get maintainable code. I would recommend not creating event handlers with Designer at all (as I did above), but many don't like it. OK, but at least use semantic names.
Also, it makes no sense to show same thing on button click, potentially again and again, but I hope this is just for study of other techniques.
Good luck,
—SA