初学者求解return语句 急!

来源:百度知道 编辑:UC知道 时间:2024/05/03 00:24:39
using System;
class Program
{
public double Add(double a, double b)
{
double MyAdd = 0;
MyAdd = a + b;
return MyAdd;
}
static void Main(string[] args)
{
Console.ReadLine(Add(1, 5));
}
}

不知哪里错了
return语句总不会用....

using System;
class Program
{
public double Add(double a, double b)
{
double MyAdd = 0;
MyAdd = a + b;
return MyAdd;
}
static void Main(string[] args)
{
Program p = new Program();
Console.ReadLine(p.Add(1, 5));
}
}

应该是
public static double Add(double a,double b)
{
....
}
函数Add(double a,double b);应该是静态的.
还有应该是
Console.WriteLine(Add(1, 5));吧...
不是要输出吗?

class Program
{
static void Main(string[] args)
{
Console.Write(Add(1,5));
}
public static double Add(double a, double b)
{
double MyAdd = 0;
MyAdd = a + b;
return MyAdd;
}

}