⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cs

📁 C#150例
💻 CS
字号:
using System;
using System.IO;
class DirAppend
{
	public static void Main(String[] args)
	{
		StreamWriter w = File.AppendText("log.txt");
		Log ("Test1", w);
		Log ("Test2", w);
		// Close the writer and underlying file.
		w.Close();
		// Open and read the file.
		StreamReader r = File.OpenText("log.txt");
		DumpLog (r);
	}

	public static void Log (String logMessage, TextWriter w)
	{
		w.Write("\r\nLog Entry : ");
		w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
			DateTime.Now.ToLongDateString());
		w.WriteLine("  :");
		w.WriteLine("  :{0}", logMessage);
		w.WriteLine ("-------------------------------");
		// Update the underlying file.
		w.Flush(); 
	}

	public static void DumpLog (StreamReader r)
	{
		// While not at the end of the file, read and write lines.
		String line;
		while ((line=r.ReadLine())!=null)
		{
			Console.WriteLine(line);
		}
		r.Close();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -