匿名函数和lamda表达式
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _06匿名函数和lamda表达式 { public delegate string DelProStr(string name); class Program { static void Main(string[] args) { string[] names = { "abCcDE", "FghIJkl", "mNOpqRST", "uvWXYz" }; //ProStr(names, SToUpper);//替换SToUpper 1、匿名函数 2、Lamda表达式 //ProStr(names, delegate(string str) { return str.ToUpper(); });//匿名函数的写法 //ProStr(names, str => str.ToUpper()); List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6, 8 }; //list.RemoveAll(n => n > 3); List<int> list2 = list.Where<int>(n => n > 3).ToList(); list.Where<int>((int n) => { return n > 3; }); IEnumerable<int> en = list.Where<int>(n => n > 3); foreach (int item in list2) { Console.WriteLine(item); } Console.ReadKey(); } static void ProStr(string[] names, DelProStr del) { for (int i = 0; i < names.Length; i++) { names[i] = del(names[i]); } } static string SToUpper(string name) { return name.ToUpper(); } } }