Writing array to text file

Posted by user3661876 on Stack Overflow See other posts from Stack Overflow or by user3661876
Published on 2014-06-07T14:49:21Z Indexed on 2014/06/07 15:24 UTC
Read the original article Hit count: 136

Filed under:

I have an array, but it won't write each index to the text file. Instead it is only writing the last index and the other indexes are not appearing. Can anyone help me to get the entire array printed to the text file?

   static void solve(int k)
    {
        if (k == N) // We placed N-1 queens (0 included), problem solved!
        {
            // Solution found!

            using (StreamWriter sw = new StreamWriter("names.txt"))
            {


                Console.Write("Solution: ");
                for (int i = 0; i < N; i++)
                {
                    Console.Write(position[i] + " ");
                    foreach (int s in position[i].ToString())
                    {

                        string list = position[i].ToString();

                        sw.Write(list + " ");


                    }

                }


                Console.WriteLine();
                sum += 1;
            }
        }

© Stack Overflow or respective owner

Related posts about c#