class1.cs

来自「C#开发教程 由浅入深 配有实例 是初学者的好帮手」· CS 代码 · 共 74 行

CS
74
字号
using System;

namespace Overloading
{
	class Log
	{
		public Log(string fileName)
		{
			// Open fileName and seek to end.
		}

		public void WriteEntry(string entry)
		{
			Console.WriteLine(entry);
		}

		public void WriteEntry(string entry, int resourceId)
		{
			Console.WriteLine(entry + " " + resourceId);
		}

		public void WriteEntry(int resourceId, string entry)
		{
			Console.WriteLine(resourceId + " " + entry);
		}

		// this won't compile: return type doesn't count
//		public int WriteEntry(string entry)
//		{
//			Console.WriteLine(entry);
//			return entry.Length;
//		}
		
		// this won't compile: access modifier doesn't count
//		protected void WriteEntry(string entry)
//		{
//			Console.WriteLine(entry);
//		}

		// either of these is OK, but not both:
//		public void WriteEntry(ref string entry)
//		{
//			Console.WriteLine(entry);
//		}

		public void WriteEntry(out string entry)
		{
			entry = "Foo";
			Console.WriteLine(entry);
		}

		public void WriteEntry(int resourceId)
		{
			Console.WriteLine(
				"Retrieve string using resource id and write to log");
		}
	}

	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			Log log = new Log("My File");
			log.WriteEntry("Entry one");
			log.WriteEntry(42);

			string s = "Foo";
			log.WriteEntry(out s);
		}
	}
}

⌨️ 快捷键说明

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