ch7_02.cs
来自「《c#技术内幕代码》」· CS 代码 · 共 38 行
CS
38 行
using System;
using System.IO;
class CH7_2
{
FileStream fs;
StreamWriter w;
public void SetupConsoleToFile()
{
fs = new FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.Write);
w = new StreamWriter(fs);
Console.SetOut(w);
}
public void DoSomeConsoleOutput()
{
Console.WriteLine("This is a test");
Console.WriteLine("This is another test");
Console.WriteLine("An Integer: {0}", 123 );
Console.WriteLine("A Floating Point Number: {0}", 123.456 );
}
public void Cleanup()
{
w.Close();
fs.Close();
}
public static void Main(String[] args)
{
CH7_2 app = new CH7_2();
app.DoSomeConsoleOutput();
app.SetupConsoleToFile();
app.DoSomeConsoleOutput();
app.Cleanup();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?