标签:
using System; using System.IO; namespace ConsoleApplication2 { delegate int NumberChanger(int n); class Program { static int num = 10; static void Main(string[] args) { NumberChanger nc1 = new NumberChanger (AddNum); nc1(25); Console.WriteLine("Value of Number:{0}",num); MyClass mc = new MyClass(); NumberChanger nc2 = new NumberChanger(mc.AddNum); nc2(35); Console.WriteLine("Value of instance:{0}",mc.num); NumberChanger nc3 = new NumberChanger(mc.MutliNum); nc3(2); Console.WriteLine("Value of instance:{0}", mc.num); Console.ReadLine(); } public static int AddNum(int p) { num += p; return num; } } class MyClass { public int num = 10; public int AddNum(int p) { num += p; return num; } public int MutliNum(int p) { num *= p; return num; } } }
标签:
原文地址:http://www.cnblogs.com/heisaijuzhen/p/4483772.html