首页 > 代码库 > 分配委托、匿名委托、委托

分配委托、匿名委托、委托

分配委托(将命名方法分配给其委托)

using System;public class GenericFunc{   public static void Main()   {      // Instantiate delegate to reference UppercaseString method      Func<string, string> convertMethod = UppercaseString;      string name = "Dakota";      // Use delegate instance to call UppercaseString method      Console.WriteLine(convertMethod(name));   }   private static string UppercaseString(string inputString)   {      return inputString.ToUpper();   }}

匿名委托

 


using System;public class Anonymous{   public static void Main()   {      Func<string, string> convert = delegate(string s)         { return s.ToUpper();};       string name = "Dakota";      Console.WriteLine(convert(name));      }}

 

分配委托、匿名委托、委托