接口与委托示例
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
///
/// degelate 的摘要说明
///
///
interface intDeg
{
void read(string str); //读取一字符串
void write(); //输出字符串
}
public class degelateDeg : intDeg
{
string strr;
public string Strr //定义一个字符串
{
set
{
strr = value;
}
get
{
return strr;
}
}
public void read(string str) //读入字符串,并跟加一些字符
{
string sttr = str + "接口与委托";
Strr = sttr;
}
public void write()
{
System.Console.Write("output" + Strr); //输出来
Console.ReadLine();
}
}
public class MainDelegate
{
public delegate void writeHandler(); //定义一个输出字符委托
public static void Main(String[] args)
{
intDeg inter = new degelateDeg(); //实例化一个类,指向接口
inter.read("suiqirui"); //调用接口的read方法
writeHandler wh = new writeHandler(inter.write); //委托去执行接口的wirte方法
wh(); //调用委托
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
///
/// degelate 的摘要说明
///
///
interface intDeg
{
void read(string str); //读取一字符串
void write(); //输出字符串
}
public class degelateDeg : intDeg
{
string strr;
public string Strr //定义一个字符串
{
set
{
strr = value;
}
get
{
return strr;
}
}
public void read(string str) //读入字符串,并跟加一些字符
{
string sttr = str + "接口与委托";
Strr = sttr;
}
public void write()
{
System.Console.Write("output" + Strr); //输出来
Console.ReadLine();
}
}
public class MainDelegate
{
public delegate void writeHandler(); //定义一个输出字符委托
public static void Main(String[] args)
{
intDeg inter = new degelateDeg(); //实例化一个类,指向接口
inter.read("suiqirui"); //调用接口的read方法
writeHandler wh = new writeHandler(inter.write); //委托去执行接口的wirte方法
wh(); //调用委托
}
}
最后结果是:outputsuiqirui接口与委托
作者: XuGang 网名:钢钢 |
出处: http://xugang.cnblogs.com |
声明: 本文版权归作者和博客园共有。转载时必须保留此段声明,且在文章页面明显位置给出原文连接地址! |