private static string UppercaseString(string inputString) {return inputString.ToUpper();} public void ForTestDelegate() { //无返回参数的委托 Action<object> action = (obj) => { Console.WriteLine("action object is {0}", obj.ToString()); }; //含返回参数的委托1 Func<string, string> convert1 = s => s.ToUpper(); //含返回参数的委托2 Func<string, string> convert2 = delegate(string s) { return s.ToUpper(); }; //含返回参数的委托3 Func<string, string> convertMethod = UppercaseString; //含返回参数的委托4 Func<int, string> convert3 = (obj) => { return obj.ToString(); }; /// action("XX000"); Console.WriteLine(convert1("abcD")); Console.WriteLine(convert2("abcD")); Console.WriteLine(convertMethod("abcD")); Console.WriteLine(convert3(153)); }