先创建一个项目
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Demo1
{
class Program
{
static void Main(string[] args)
{
}
}
}
接口:一种特殊的类,为行为提供一种合同或约定
对于类和他的派生拍中的方法,定义一个统一访问的方式,就可以使用接口interface定义开头的行为通过程序去实现对定,风扇,等等智能电器的控制定义接口的语法,访问修饰符interface【名称 前缀】
public interface Iswitch
{
//接口中没有字段,没有成员属性,只有方法,而且不能有修饰符
void TurnOn();
void TurnOff();
}
然后再建立一个个类,调用这个类,先建立一个风扇的类
using System;
using System.Collections.Generic