我似乎无法将我的数组保存到我的文本文件中

时间:2015-11-13 16:45:15

标签: c#

我创建了一个输入字符串输入的文件 在一个数组中。输入所有数组条目后,它们将存储在TeXt文件中。它们必须按升序存储 。但是我在存储文本文件时遇到了麻烦。我创建了数组,当我输入名称时,它们以升序显示在控制台应用程序中

这是代码

namespace Sandra2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] storeNames = new string[56];
            string s = "\n";
            string time = DateTime.Now.ToString("yyy-MM-dd-HH-mm-ss");
            StreamWriter File = new StreamWriter("C:\\mine\\Output" + time + ".txt");

            Console.WriteLine("Enter Authors " + " & " + "Enter Book title");
            File.WriteLine("Authors Name" + " \t   " + " Book Title");


            for (int i = 0; i < storeNames.Length; i++)
            {
                string Author;
                 Author = Console.ReadLine();

                 Array.Sort<String>(storeNames);
                 if (Author == "stop")
                 {
                     break;
                 }
                 storeNames[i] = Author;
                 storeNames[i] += "\n";


                 File.WriteLine(Author.ToString());
                 File.Close();
                 File.WriteLine("\n");
                 File.WriteLine("The names in ascending order are: {0}", s);
                 Console.ReadKey();
            }

            foreach (string num in storeNames)
            {
                s += num;
            }
            }
        }
    }

0 个答案:

没有答案