Action<T> 委托

using System;
using System.Windows.Forms;

delegate void DisplayMessage(string message);

public class TestCustomDelegate
{
public static void Main()
{
DisplayMessage messageTarget;

if (Environment.GetCommandLineArgs().Length > 1)
messageTarget = ShowWindowsMessage;
else
messageTarget = Console.WriteLine;

messageTarget("Hello, World!");
}

private static void ShowWindowsMessage(string message)
{
MessageBox.Show(message);
}
}




using System;
using System.Windows.Forms;

public class TestAction1
{
public static void Main()
{
Action<string> messageTarget;

if (Environment.GetCommandLineArgs().Length > 1)
messageTarget = ShowWindowsMessage;
else
messageTarget = Console.WriteLine;

messageTarget("Hello, World!");
}

private static void ShowWindowsMessage(string message)
{
MessageBox.Show(message);
}
}


posted @ 2011-11-12 20:29  陈跳跳  阅读(158)  评论(0编辑  收藏  举报