using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test1
{
class Program
{
public delegate double MProcess(double a, double b);
public static double Add(double a, double b)
{
return a + b;
}
public static double Multity(double a, double b)
{
return a * b;
}
static void Main(string[] args)
{
while (true)
{
int choose = Convert.ToInt32(Console.ReadLine());
MProcess process;
if (choose == 1)//赋值方式
{
process = Add;
}
else if(choose == 2)
{
process = Multity;
}
else if (choose == 11)//new 方式
{
process = new MProcess(Add);
}
else
{
process = new MProcess(Multity);
}
string r = Console.ReadLine();
string[] pars = r.Split(new char[1] { ' ' });
int a = Convert.ToInt32(pars[0]);
int b = Convert.ToInt32(pars[1]);
Console.WriteLine("Result : {0}", process(a, b));
}
}
}
}
C#委托 delegate
最新推荐文章于 2024-08-14 12:11:42 发布