接口

using System;
namespace testInterface
{
public interface IAnimal //必须是public或者internal
{//要不要加访问修饰符? 不要
string show();
string xianshi();
double Width{get;set;}
}
class Dog:IAnimal
{
public string show() //此处必须是public,internal都不可以
{
return "Dog Move,here and there:width=" + width;
}
string IAnimal.xianshi()
{
return("若是显式实现,不得使用任何访问修饰符");
}
//实现属性Property
double width=0;
public double Width
{
get
{
return width;
}
set
{
width = value;
}
}
}
class myApp
{
static void Main_89() //
{
Dog d = new Dog();
d.Width=50;
Console.WriteLine(d.show());
}
}
}
/*
* 声明接口必须是internal或者public; protected和private不可以
* 接口成员在声明时不得使用任何访问修饰符
* 接口成员在类中被实现时:
* 1.若是显式实现,不得使用任何访问修饰符
* 2.若非显示实现,必须用public,internal都不可以
* */



浙公网安备 33010602011771号