Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在C#控制台应用程序中保存输入_C#_Console Application - Fatal编程技术网

如何在C#控制台应用程序中保存输入

如何在C#控制台应用程序中保存输入,c#,console-application,C#,Console Application,我需要有关在指定文本文件中保存输入的帮助,但我不知道如何在该文件中创建和保存输入。有人能帮我介绍一下saveStudent函数吗 private static void addStudent() { Console.WriteLine("Name: "); string ime = Console.ReadLine(); Console.WriteLine("Lastname: ");

我需要有关在指定文本文件中保存输入的帮助,但我不知道如何在该文件中创建和保存输入。有人能帮我介绍一下saveStudent函数吗

private static void addStudent()
        {
            Console.WriteLine("Name: ");
            string ime = Console.ReadLine();

            Console.WriteLine("Lastname: ");
            string prezime = Console.ReadLine();

            Console.WriteLine("Subject: ");
            string kurs = Console.ReadLine();

            saveStudent();
        }

您只需要将所有输入保存到一个字符串中,如

string Str = ime + prezime + kurs;
然后就

System.IO.File.WriteAllText(@"C:\ConsoleInput.Txt",Str);

在saveStudent()函数中

string Str = ime + prezime + kurs;
saveStudent(Str);
public string saveStudent(string s)
{
    System.IO.File.WriteAllText(@"C:\ConsoleInput.Txt",Str); //You can choose your own path.
}