一、传统的委托定义及调用
C# 代码
using System;
using System.Windows.Forms;
public delegate void DisplayMessage();
public class testTestDelegate
{
public static void Main()
{
DisplayMessage showMethod = DisplayToWindow();
showMethod();
}
public static void DisplayToWindow()
{
MessageBox.Show("http://www.studyofnet");
}
}
二、System.Action实现委托
C# 代码
using System;
using System.Windows.Forms;
public class testTestDelegate
{
public static void Main()
{
Action showMethod = DisplayToWindow;
showMethod();
}
public static void DisplayToWindow()
{
MessageBox.Show("http://www.studyofnet");
}
}
三、使用Lambda的方式调用System.Action实现委托
C# 代码
using System;
using System.Windows.Forms;
public class testTestDelegate
{
public static void Main()
{
Action showMethod = () =>{ MessageBox.Show("http://www.studyofnet"); };
showMethod();
}
}
更多推荐
System.Action委托
发布评论