How can print number only 6-digit start from 000000-999999 by C#
string st = "";
for (int i = 0; i <= 999999; i++)
{
st += i.ToString("000000") + "\n";
}
MessageBox.Show(st);
How can print number only 6-digit start from 000000-999999 by C#
string st = "";
for (int i = 0; i <= 999999; i++)
{
st += i.ToString("000000") + "\n";
}
MessageBox.Show(st);
I'm not sure what issue you're facing with your code, but you might want to consider using a StringBuilder
instead of a string
. Every time you add to a string
you're actually getting a new instance of the string
and that many new instances can eat up some memory. Whereas a StringBuilder will change itself, instead of creating new instances. See Difference between string and StringBuilder
using System;
using System.Text;
public class Program
{
public static void Main()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= 999999; i++)
{
sb.AppendLine(i.ToString("000000"));
}
Console.WriteLine(sb);
}
}