Hello guys,
I have a small problem, and searching for solution. I am trying to write program that will write all numbers from 00000000 to 99999999 into txt file.
Result in txt should look like this
00000001
00000002
00000003
So, how can I do this?

Thanks

Here's one technique:

using System.IO;

namespace DW_398205
{
   class Program
   {
      static void Main(string[] args)
      {
         string strTempFileName = Path.GetTempFileName();
         using (StreamWriter fileOut = new StreamWriter(strTempFileName))
         {
            for (int i = 0; i < 100; i++)
            {
               fileOut.WriteLine("{0}", i.ToString().PadLeft(8, '0'));
            }

            fileOut.Close();
         }
      }
   }
}

Here's another technique:

using System.IO;

namespace DW_398205
{
   class Program
   {
      static void Main(string[] args)
      {
         string strTempFileName = Path.GetTempFileName();
         using (StreamWriter fileOut = new StreamWriter(strTempFileName))
         {
            for (int i = 0; i < 100; i++)
            {
               fileOut.WriteLine("{0}", i.ToString("D8"));
            }

            fileOut.Close();
         }

         File.Delete(strTempFileName);
      }
   }
}

And here is a reference: http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#DFormatString

Edited 5 Years Ago by thines01: Added reference

Comments
Great help! :)
This question has already been answered. Start a new discussion instead.