标题:[求助]“一个基础问题”
取消只看楼主
zhenglei
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2006-12-4
 问题点数:0 回复次数:0 
[求助]“一个基础问题”

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));
double param2 = Convert.ToDouble(input.Substring(commapos + 1, input.Length - commapos - 1));
Console.WriteLine("enter m to multiply or d to divide:");
input = Console.ReadLine();
if (input == "m")
process = new processdelegate(multiply);
else
process = new processdelegate(divide);
Console.WriteLine("result: {0}", process(param1, param2));
Console.ReadKey();
}
}

搜索更多相关主题的帖子: 基础 
2006-12-04 14:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-107183-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.120687 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved