📜  lambda C# 选择任何执行操作列表调用函数 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:47.346000             🧑  作者: Mango

代码示例1
myList.ForEach(p => myFunc(p));

//or

public static void ForEach(this IEnumerable source, Action action)
{
    foreach(T item in source)
        action(item);
}
Which means you can now do:

myList.Where( ... ).ForEach( ... );

//or

string[] items = (new string[] { "d", "f" }).
    Select(x => new Func(() => { 
        //Do something here...
        Console.WriteLine(x); 
        return x.ToUpper(); 
    }
)).Select(t => t.Invoke()).ToArray();

//or

var functions = (new string[] { "d", "f" }).
       Select(x => new Func(() => { 
          //Do something here...
          Console.WriteLine(x); 
          return x.ToUpper(); 
       }));
string[] items = functions.Select(t => t.Invoke()).ToArray();