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

📄 class1.cs

📁 c#网络编程及应用-刘瑞新
💻 CS
字号:
using System;
namespace TestInterface
{
	interface Ifunction
	{
		int sum(int x1,int x2);
	}
	class MyTest:Ifunction
	{
		//实现接口Ifunction1中的方法
		int Ifunction.sum(int x1,int x2)
		{
			return x1+x2;
		}
	}
	class MainClass
	{
		public static void Main()
		{
			//直接访问实例,会提示“MyTest不包含对sum的定义”的错误
			//因为sum是显式实现接口,只能通过接口调用
			//MyTest a=new MyTest();
			//Console.WriteLine(a.sum(10,20)); 
			//通过接口访问实例
			Ifunction b=new MyTest();
			Console.WriteLine(b.sum(20,30));
			Console.Read();
		}
	}
}

⌨️ 快捷键说明

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