













Action 和 Func
action没有返回值。
func有返回值。
Action<T> // Action<T> 是系统预定义的委托类型 public delegate void Action<in T>(T obj); // 简化表示 // 所以 Action<object> 相当于: public delegate void MyAction(object obj); // 接收object参数,无返回值
// 无参数 Action action1 = () => Console.WriteLine("无参数"); // 一个参数 Action<string> action2 = (s) => Console.WriteLine(s); // string参数 Action<object> action3 = (o) => Console.WriteLine(o); // object参数 // 多个参数 Action<int, string> action4 = (i, s) => Console.WriteLine($"{i}:{s}"); Action<int, int, int> action5 = (a, b, c) => Console.WriteLine(a + b + c);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。