简体   繁体   中英

C# Console.Write print out in text file?

Can I make code like this to print out in a text file using Console.Write ?

 Console.Write(" Enter your ID: ");
 int ID = int.Parse(Console.ReadLine());
 Console.Write(" Enter your Name: ");
 string Name = Console.ReadLine();
 Console.WriteLine(" Thank you! your logged in as" +Name+ +ID);

Please Help!

Thanks in Advance.

I don't know why you need to write in a file in your particular case but if you want Console.WriteLine to write in a file you may use Console.SetOut(sw);

Console.WriteLine("Hello World");
FileStream fs = new FileStream("Test.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
Console.SetOut(sw);
Console.WriteLine("Hello file");
sw.Close();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM