C#中接口不可以实例化,那IRingSequence rs又是什么意思呢?

来源:百度知道 编辑:UC知道 时间:2024/05/16 23:57:35
using System;
interface ISequence
{
int Count{get;set;}
}
interface IRing
{
void Count(int i);
}
interface IRingSequence:ISequence,IRing{}
class C
{
void Test(IRingSequence rs){ //这里......
((ISequence)rs).Count=1;
((IRing)rs).Count(1);
}
}

有时候方法里的参数也会是:类名 变量,比如:
public class Baby
{
float Temprature;

public event BabyIllEventHander BabyIsILL;

public void BabyFallIll()
{ if (this.Temprature!=37) { BabyILLEventArgs e=new BabyILLEventArgs(temprature);

BabyIsIll(this,e); }
}
}

public class Adult
{
public Adult(Baby baby) //这里......
{
baby.BabyIsIll+=new BabyIllEventHandler(GoToHospital);
}
}

这些算不算是实例化,或者引用什么的?请高手帮忙解释下,谢谢!

在调用类 c.Test()方法的之前就要实现这个接口
IRingSequence rs = new Test();
c.Test(rs)中,IRingSequence rs 这个只是作为参数传到方法里面去用,并没有实例.
接口永远不能直接实例化。--msdn
但可以说这样用

接口 实例 = new 实现接口的类() ;