Q:

Read, write, from and to a file using C#

Very simple and straight forward, I want to read from a file; convert the string value to an int, iterate using "for statement" and write the file into another file. When writing, it should write each digit on a new line.  I want to use the WriteAllLines static method of File class. It only accepts a string array, how do I get this done? My code snippet is this:
static void Main(string[] args)
        {
            String Readfiles = File.ReadAllText(@"C:\Users\ken4ward\Desktop\Tidy\WriteLines.txt");
            Int32 myInt = Int32.Parse(Readfiles);

            for (int i = 0; i < myInt; ++i)
            {
                Console.WriteLine(i);
                Console.ReadLine();  
                String[] start = new String[i];
            File.WriteAllLines(@"C:\Users\ken4ward\Desktop\Tidy\writing.txt", start);
            }
        }

It is very simple. With a bunch of codes, an output of an iteration is written to a .txt file. The iteration only counts how many times a method is called. This part is perfectly done. If the method is called 10 times, it simply writes 10. The second class file reads this file and writes it to  another .txt file. What I want to do is that since the first file writes only a digit. As an example - 10, what is written in the second file should like this:
1
2
3
4
5
6
7
8
9
10    

meaning that it writes each digit on a new line. The problem is that it does not write to the txt file.

A:

The problem is that you are declaring your string array inside the loop and never populating it with anything.  Move that string array outside the loop instead.  Also, I don't think you want to write the file every time through the loop, so move file write outside the loop too.
static void Main(string[] args)
{
    String Readfiles = File.ReadAllText(@"C:\Users\ken4ward\Desktop\Tidy\WriteLines.txt");
    Int32 myInt = Int32.Parse(Readfiles);

    //Declare array outside the loop
    String[] start = new String[myInt];

    for (int i = 0; i < myInt; ++i)
    {
        //Populate the array with the value (add one so it starts with 1 instead of 0)
        start[i] = (i + 1).ToString();

        Console.WriteLine(i);
        Console.ReadLine();  
    }

    //Write to the file once the array is populated
    File.WriteAllLines(@"C:\Users\ken4ward\Desktop\Tidy\writing.txt", start);
}

