When you write:
Label2.Text =Convert.ToString(x);
Inside a loop, you will only ever get teh last value to used, just teh same as if you said:
int x = 0;
for (int i = 0; i < 10; i++)
{
x = i;
}
X will always equal the final value in the loop: 9.
You can do what you want with strings:
Label2.Text += Convert.ToString(x);
But that's not a good idea, as string are immutable - every time you add to a string you create a new string, and copy the old and new data into it. That's pretty inefficient, particularly when you generate a lot of numbers!
A better solution is to use a StringBuilder:
StringBuilder sb = new StringBuilder();
string sep = "";
for (int i = 0; i < 10; i++)
{
sb.AppendFormat("{0}{1}", sep, i);
sep = ", ";
}
And then use the output of the that after the loop:
Label2.Text = sb.ToString();
But a couple of details to add:
1) Don't use Convert for input or output - it has a place, but this isn't it! When you use Convert.ToInt32 on user input, you app will crash if the user mistypes.
A much better solution here is to use TryParse:
int z;
if (!int.TryParse(TextBox1.Text, out z))
{
report problem to user
return;
}
And there is no need to use Convert for output:
... = x.ToString;
Is a lot clearer!
2) Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
3) Stop using single character variable names! Using descriptive names which explain what the variable is used for makes your code a lot easier to read and understand (and generally is as quick as single character ones thanks to Intellisense).