C#中可以使用委托来调用函数,具体这样实现的好处有待以后慢慢领悟,下面是实现的简单代码,与大家分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
delegate double ProcessDelegate(double param1 ,double param2); //定义一个委托,参数类型和返回值很相似于函数
static double Multiply(double param1 ,double param2) //定义全局函数
{
return param1 * param2;
}
static double Divide(double param1 ,double param2) //定义全局函数
{
return param1 / param2;
}
static void Main(string[] args)
{
ProcessDelegate process; //有委托类型声明变量
Console.WriteLine("Enter 2 numbers separated with a comma:");
string input = Console.ReadLine();
int commaPos = input.IndexOf (','); // 请求有逗号分隔的两个数
double param1 = Convert.ToDouble(input.Substring(0,commaPos