例如:
using System;
using System.Collections.Generic;
using System.Text;namespace TestMe
{
interface myinterface
{
void aa();
}
class a : myinterface
{
public void aa()
{
Console.WriteLine("aa");
}
public void aaa()
{
Console.WriteLine("aaa");
}
} class Program
{
static void Main(string[] args)
{
myinterface b;
b = new a();
b.aa();
/*
如果我要用aa这个方法的话用
a test2 = new a(); test2.aa(); 这样也行啊,接口有什么好处啊?什么时候该用接口?
*/
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;namespace TestMe
{
interface myinterface
{
void aa();
}
class a : myinterface
{
public void aa()
{
Console.WriteLine("aa");
}
public void aaa()
{
Console.WriteLine("aaa");
}
} class Program
{
static void Main(string[] args)
{
myinterface b;
b = new a();
b.aa();
/*
如果我要用aa这个方法的话用
a test2 = new a(); test2.aa(); 这样也行啊,接口有什么好处啊?什么时候该用接口?
*/
Console.ReadKey();
}
}
}
解决方案 »
- 关于bitmap位图大小的思考
- 【提问】关于析构函数的执行问题
- 这个问题该怎么解决,请赐教
- x.Split('|'); 这里是单引号,如果是双引号就必须用Regex.Split(x, "\\|"); 只是哪门子规定啊?哪里有介绍?
- 高分求救!!!关于在GridList里面让固定的一条数据在最底下显示的方法
- C#读取文件出错
- 为什么我开发的软件速度这么慢?怎么办?
- 导出excel 时释放资源的问题!
- 我用web程序生成了word的document的对象,怎么通过网页输出word文件?不是保存到
- 100分求助c#模拟注册汽车之家
- 如何在winform里复制IE网页中用鼠标选定的内容到剪贴板
- 如何单击datagrid获得单击行的值?
比如:电视类和马桶类都实现了这个接口,这样就可以使用一个操作,打开所有的电视机和马桶,单独实现功能也是可以的,但是会比较零乱。interface ObjCanOpen
{
void Open();
}class TV : ObjCanOpen
{...}class Closestool : ObjCanOpen
{...}void OpenAll
{
ArrayList al = new ArrayList();
al.Add(new TV());
al.Add(new Closestool());
foreach(ObjCanOpen o in al)
{
o.Open()
}
}
接口在设计模式中应用很多,比如模板方法……