新手求助,期待解答……
程序代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class UsingDelegates { static void Main(string[] args) { long length1=10; long length2 = 15; Console.WriteLine("边长为{0}的正方形面积为:{1}",length1,Square (length1).ToString ()); Console.WriteLine("半径为{0}的圆形面积为:{1}", length2, Circle(length2).ToString()); Console.ReadLine(); } public static double Square(long length) { double area; area = Math.Pow(length, 2); return area; } public static double Circle(long length) { double area; area = (4 / 3) * Math.PI * Math.Pow(length, 3); return area; } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class UsingDelegates { public delegate double myDelegate(long length); static void Main(string[] args) { long length1 = 10; long length2 = 15; myDelegate myDelegate1 = new myDelegate(Measure.Square); myDelegate myDelegeta2 = new myDelegate(Measure.Circle); Console.WriteLine("边长为{0}的正方形面积为:{1}", length1, myDelegate1(length1).ToString()); Console.WriteLine("半径为{0}的圆形面积为:{1}", length2, myDelegeta2(length2).ToString()); Console.ReadLine(); } } class Measure { public static double Square(long length) { double area; area = Math.Pow(length, 2); return area; } public static double Circle(long length) { double area; area = (4 / 3) * Math.PI * Math.Pow(length, 3); return area; } } }求助各位,两段代码的区别及使用效果?谢谢了!