namespace trains
{
interface IliveBirth
{
string Babycalled();
}
class Animal { }
class cat:Animal ,IliveBirth
{
string IliveBirth.Babycalled() //实现接口的实现方法这必须带public标识符或者用显式接口成员。
}
}
class dog:Animal ,IliveBirth
{
public string Babycalled() //同上
{
return "Der Hund";
}
}
class bird:Animal
{ }
class Program
{
static void Main()
{
Animal[] animalArray = new Animal[3];
animalArray[0] = new cat();
animalArray[1] = new dog();
animalArray[2] = new bird();
foreach (Animal a in animalArray )
{
IliveBirth b = a as IliveBirth;
if(b!=null)
{
Console.WriteLine("Das Tier ist {0}", b.Babycalled());
}
}
}
}
}
{
interface IliveBirth
{
string Babycalled();
}
class Animal { }
class cat:Animal ,IliveBirth
{
string IliveBirth.Babycalled() //实现接口的实现方法这必须带public标识符或者用显式接口成员。
{ //如果直接写 string BabyCalled() 会显示无法实现接口成员,因为它不是公共的。
return "Die Katze"; //应该是因为接口声明中的成员都是隐式public而类中的成员都是隐式private的。}
}
class dog:Animal ,IliveBirth
{
public string Babycalled() //同上
{
return "Der Hund";
}
}
class bird:Animal
{ }
class Program
{
static void Main()
{
Animal[] animalArray = new Animal[3];
animalArray[0] = new cat();
animalArray[1] = new dog();
animalArray[2] = new bird();
foreach (Animal a in animalArray )
{
IliveBirth b = a as IliveBirth;
if(b!=null)
{
Console.WriteLine("Das Tier ist {0}", b.Babycalled());
}
}
}
}
}