方式一、用委托作为形参,把结果传回实参
方式二、通过接口实现
方式三、通过事件关联,适用桌面应用程序
方式四、子窗体调用父窗体的函数(委托)
方式一、用委托作为形参,把结果传回实参
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Child chld = new Child();
chld.GetURL((url) =>
{
Response.Write(url);
//取得结果:http://microsoft-zh.cn
});
}
}
public class Child
{
//创建委托
public delegate void GetURLDelegate(string url);
public void GetURL(GetURLDelegate func)
{
func("http://microsoft-zh.cn");
}
}
</