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

📄 testdelegates.cs

📁 北大青鸟内部资料
💻 CS
字号:
using System;

namespace Example_3
{
	/// <摘要>
	/// 该程序演示委托的用法。
	/// </摘要>
	
	class Delegates
	{
		// 委托定义
		public delegate int Call(int num1, int num2);
	
		class Math
		{
			// 乘法方法
			public int Multiply(int num1, int num2)
			{
				return num1*num2;
			}
	
			// 除法方法
			public int Divide(int num1, int num2)
			{	
				return num1/num2;
			}
		}

		class TestDelegates
		{
			/// <摘要>
			/// 应用程序的主入口点。
			/// </摘要>
			[STAThread]
			static void Main(string[] args)
			{
				// 存储结果的变量
				int result;

				// 委托的对象
				Call objCall;
				// Math 类的对象
				Math objMath = new Math();
	
				// 将方法与委托关联起来
				objCall = new Call(objMath.Multiply);

				// 实例化该委托
				result = objCall(5, 3);
				System.Console.WriteLine("结果为 {0}", result);		  
			}	
		}
	}
}

⌨️ 快捷键说明

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