using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleTest
{
public delegate void DelegCalc(params int[] oParams);
public class delegateTest
{
public static void Calc(DelegCalc deleg, params int[] oParams)
{
deleg(oParams);
}
//三角形
public static void CalcArea_Triangle(int[] iWidth)
{
Console.WriteLine("三角形 宽度:{0},高度:{1},面积:{2}", iWidth[0], iWidth[1], iWidth[0] * iWidth[1] / 2.0);
}
//长方形
public static void CalcArea_Rectangle(int[] iWidth)
{
Console.WriteLine("长方形 宽度:{0},高度:{1},面积:{2}", iWidth[0], iWidth[1], iWidth[0] * iWidth[1]);
}
//梯形
public static void CalcArea_Trapezoid(int[] iA)
{
Console.WriteLine("梯形 上底:{0},下底:{1},高度:{2},面积:{3}", iA[0], iA[1], iA[2], (iA[0] + iA[1]) * iA[2] / 2.0);
}
//圆
public static void CalcArea_Circle(int[] iR)
{
Console.WriteLine("圆 半径:{0},面积:{1}", iR[0], Math.PI * iR[0] * iR[0]);
}
//三角形周长
public static void CalcGirth_Triangle(int[] iA)
{
Console.WriteLine("三角形 边1:{0},边2:{1},边3:{2},周长:{3}", iA[0], iA[1], iA[2], iA[0]+ iA[1]+iA[2]);
}
public static void CalcGirth_Rectangle(int[] iA)
{
Console.WriteLine("长方形 边1:{0},边2:{1},周长:{2}", iA[0], iA[1], (iA[0] + iA[1]) * 2);
}
public static void CalcGirth_Trapezoid(int[] iA)
{
Console.WriteLine("梯形 边1:{0},边2:{1},边3:{2},边4:{3},周长:{4}", iA[0], iA[1], iA[2], iA[3], iA[0] + iA[1] + iA[2] + iA[3]);
}
public static void CalcGirth_Circle(int[] iR)
{
Console.WriteLine("圆 半径:{0},周长:{1}", iR[0],2*Math.PI*iR[0]);
}
}
class delegateClass2
{
static void Main()
{
delegateTest.Calc(delegateTest.CalcGirth_Circle, new int[]{3});//圆周长
delegateTest.Calc(delegateTest.CalcGirth_Rectangle, new int[] { 3,4 });//长方形周长
delegateTest.Calc(delegateTest.CalcGirth_Trapezoid, new int[] { 3, 4,5,6 });//梯形周长
delegateTest.Calc(delegateTest.CalcGirth_Triangle, new int[] { 3, 4, 5, 6 });//三角形周长
delegateTest.Calc(delegateTest.CalcArea_Circle, new int[] { 3 });//圆面积
delegateTest.Calc(delegateTest.CalcArea_Rectangle, new int[] { 3,4 });//长方形面积
delegateTest.Calc(delegateTest.CalcArea_Trapezoid, new int[] { 3, 4,5 });//梯形面积
delegateTest.Calc(delegateTest.CalcArea_Triangle, new int[] { 3, 4});//三角形面积
Console.ReadLine();
}
}
}
运行效果: