如何将Lambda表达式转换为Func <>变量

use*_*817 1 c# variables lambda func

我有搜索文件的代码.现在有Lambda Expression用于过滤.如何将Expression转换为Func<string>变量.谢谢

代码:

Directory.GetFiles(folder, "*" + KeyWord + "*").Where(f => formatFile.Contains(f.Split('.').Last().ToLower()));
Run Code Online (Sandbox Code Playgroud)

变量:

Func<string> Lambda = ?? (f => formatFile.Contains(f.Split('.').Last().ToLower())) \\ convert the Expression;
Run Code Online (Sandbox Code Playgroud)

CSJ*_*CSJ 6

它应该像以下一样简单:

Func<string,bool> lambda = f => formatFile.Contains(f.Split('.').Last().ToLower());
Run Code Online (Sandbox Code Playgroud)

bool似乎是你缺少的部分(这个表达式接受一个字符串并返回一个bool).