C# Delegates - CSharp Custom Type

CSharp examples for Custom Type:delegate

Description

C# Delegates

Demo Code

using System;// ww  w .j  av a2s  .  c om
delegate int IntConverter(int n);
class TestDelegate {
   static int num = 10;
   public static int AddNum(int p) {
      num += p;
      return num;
   }
   public static int MultNum(int q) {
      num *= q;
      return num;
   }
   public static int getNum() {
      return num;
   }
   static void Main(string[] args) {
      IntConverter nc1 = new IntConverter(AddNum);
      IntConverter nc2 = new IntConverter(MultNum);
      nc1(25);
      Console.WriteLine("Value of Num: {0}", getNum());
      nc2(5);
      Console.WriteLine("Value of Num: {0}", getNum());
   }
}

Result


Related Tutorials