using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
public class Temp
{
public string name { get; set; }
public int value { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<Temp> list = new List<Temp>(); //假定这是来自其他某函数的返回值,一个很长的list
var resultList = new List<Temp>() { };
bool a = RandomTF();
//Func<bool, Temp> test = null;
Predicate<Temp> match;
if (a)
{
match = temp => temp.value > 0;
}
else
{
match = temp => temp.value > 0 && temp.name.Length > 3;
}
resultList = list.FindAll(match);
var b = resultList;
}
private static bool RandomTF()
{
Random r = new Random();
var a = r.Next(1,10);
return a % 2 == 0;
}
}
}
C#动态匿名函数用法示例
最新推荐文章于 2023-10-30 14:23:39 发布