System.Action委托
System.Action委托一、传统的委托定义及调用
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.com");
}
}
二、System.Action实现委托
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.com");
}
}
三、使用Lambda的方式调用System.Action实现委托
using System;
using System.Windows.Forms;
public class testTestDelegate
{
public static void Main()
{
Action showMethod = () =>{ MessageBox.Show("http://www.studyofnet.com"); };
showMethod();
}
}