参考代码:
using System; using System.Collections.Generic; using System.Linq; namespace FuncActionDemo { class FuncActionTest { public void Test1(List<int> data,Func<int,bool> filter) { var result = data.Where(x => filter(x)).ToList(); result.ForEach(x => { Console.WriteLine(x); } ); } public void Test2(List<int> data,Action<int, int>action) { var d = data.OrderBy(x => x).ToList(); action(d[0], d[1]); } } class Program { static void Main(string[] args) { FuncActionTest funcTest = new FuncActionTest(); List<int> data = new List<int> { 1, 2, 4, 7, 8, 9 }; funcTest.Test1(data, x => { if (x % 2 == 0) return true; else return false; }); funcTest.Test1(data, x => { return FilterEven(x); }); funcTest.Test1(data, FilterEven); Console.WriteLine("-----------"); funcTest.Test2(data,Add); } static bool FilterEven(int s) { if (s % 2 == 0) return true; else return false; } static void Add( int a, int b) { Console.WriteLine(a + b); } } }
标签:Test1,return,C#,void,List,funcTest,Func,Action,data From: https://www.cnblogs.com/exesoft/p/16945378.html