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

📄 class1.cs

📁 C#开发教程 由浅入深 配有实例 是初学者的好帮手
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -