c# 接口调用
来源:百度知道 编辑:UC知道 时间:2024/05/14 16:45:06
是不是用类继承接口,能后在定义这个接口的相同参数和方法名呀,而继承这个接口的类中的方法就可以实现这个接口的功能呀
interface Ix//接口不能有成员函数,可以有函数和属性,但不能在接口里实现
{
void f();//接口里面的函数不写函数体
}
举例
interface kebijiao
{
int bijiao(object obj);
}
class 箱子 : kebijiao
{
int 长;
int 宽;
int 高;
public int 体积
{
get { return 长 * 宽 * 高; }
}
public 箱子(int a, int b, int c)
{
this.长 = a;
this.宽 = b;
this.高 = c;
}
public int bijiao(object obj)
{
箱子 a = (箱子)obj;
if (this.体积 > a.体积)
return 1;
else if (this.体积 < a.体积)
return -1;
else
return 0;
}
class Program
{
static void paixu(kebijiao[] x)
{
for (int i = 0;