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();
}
}
其中 int commapos = input.IndexOf(',');
double param1 = Convert.ToDouble(input.Substring(0, commapos));
double param2 = Convert.ToDouble(input.Substring(commapos + 1, input.Length - commapos - 1));
他们在干什么?
input.Substring(0, commapos)
input.Substring(commapos + 1, input.Length - commapos - 1)
是什么意思?
input.Substring()是什么意思?
input.IndexOf(',') 是什么意思?
input.IndexOf()是什么意思?
谢谢各位大哥了!!!!