惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - MainIsUsed

svg札记 rabbitmq 小记 nfc相关 MI卡UID oracle9i导入导出命令 (转)C++中指针和引用的区别 .net下的office开发(visio对象) 关于DataTable的GetChanges()方法 【转】C#中的非安全编程(key:unsafe,fixed) Oracle中UTL_FILE包的UTL_FILE.FOPEN用法 c# 获取串口设备的输入(unsigned char *和 char*) URL字符串编码 笔记HTML - MainIsUsed - 博客园 .net导出为powerpoint的一些参考代码 关于ClickOnce 发布过程中的错误:要求高版本的CAPICOM.dll Oracle EXTRACT()函数与to_char() 函数 在 WinForm 中完整支持在多级目录中保存的 ASP.NET (转) - MainIsUsed (转)实现基于事件通知的.Net套接字 (转)什么是套接字(Socket)?
c#接口使用方法 - MainIsUsed - 博客园
MainIsUsed · 2007-11-02 · via 博客园 - MainIsUsed

using System;

namespace ClassLibrary2
{
interface IEmploy //接口
{
void Speak(); //方法
}


class Hello:IEmploy //Hello类实现接口
{

public void Speak() //实现方法
{
Console.WriteLine("Hello:朋友");
}

}

class Sorry:IEmploy //Sorry类实现接口
{

public void Speak() //实现方法
{
Console.WriteLine("Sorry:朋友");
}

}
}
实现

//直接调用
IEmploy Ie = new Hello();
Ie.Speak(); //调用Hello类实现的接口

IEmploy Ie = new Sorry();
Ie.Speak();

//反射调用 记住反射的空间引用 using System.Reflection;

Assembly Asm = Assembly.Load("ClassLibrary2");//反射出空间

Type type = Asm.GetType("ClassLibrary2.Hello");//反射出空间下的类

object AssClas = Activator.CreateInstance(type);//动态实力化反射回来的指定空间下的指定类

IEmploy Ie = (IEmploy)AssClas; ////转换为接口类型

//常用的就这几种方法