一 :Lambda表达式 做函数参数
二 : 代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace CsharpConsoleApplication
{
public delegate void MyDelegate(string str);//声明一个没有参数没有返回值的委托函数
class Program
{
static void Main(string[] args)
{
HandleStr("hello world", (str) => { str = str.ToUpper(); System.Console.WriteLine(str); });//Lambda表达式:
HandleStr("HELLO WORLD", (str) => { str = str.ToLower(); System.Console.WriteLine(str); });//Lambda表达式:
System.Console.ReadLine();
}
static void HandleStr(string str ,MyDelegate del)//委托作函数参数,有点多态的意识
{
del(str);//委托的调用
}
}
}