1.Action<SmsData> addData = d => SmsService.AddData(d); å¦ä½ç解ï¼
Action<SmsData> addData = d => SmsService.AddData(d); å¦ä½ç解ï¼
å æ解å¦ä¸ï¼
d => SmsService.AddData(d); //转æ¢ä¸
public void temp(SmsData d)
{
SmsService.AddData(d);
}
ä¸èè线ç¨å®å ¨ï¼å次翻è¯ï¼
Action<SmsData> addData = temp;
addData(obj);
public void temp(SmsData d)
{
SmsService.AddData(d);
}
çç¥äºä¸ä¸ªå½æ°ï¼ç¨Lamada表达å¼åç è¿ç§åæ³å¾é¿è§ åé¢ä½ å¨ç¼ç¨çæ¶åè½çå°ä¸å°
è¿ä¸ªæ¯ä¸ä¸ªå§æï¼å¨ä½¿ç¨ Action<T> å§ææ¶ï¼ä¸å¿ æ¾å¼å®ä¹ä¸ä¸ªå°è£ åªæä¸ä¸ªåæ°çæ¹æ³çå§æã
å®ä¹ï¼
public delegate void Action<in T>(T obj)//ç解ææ³åçã
DEMO:
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);
}
}