方法(参数的传递)

//有方法名,有参数个数,有参数类型,有参数顺序(参数的传递)

namespace ConsoleApplication3
{
class Program
{
public static int Add(int x, int y)//使用静态修饰词static 需要用类名.出来
{
return x + y;
}
public double Add(int x, double y)//无静态修饰词static 实例化对象.出来
{
return x + y;
}
public int Add(int x, int y,int z)
{
return x + y + z;
}
static void Main(string[] args)
{
Program program = new Program();//实例化Program类对象
int q = 3;//参数的传递与变量名无关 与参数个数,参数类型,参数顺序相关
int w = 5;
int e = 7;
double y1 = 5.5;
Console.WriteLine(q + "+" + w + "=" + Program.Add(q, w));
Console.WriteLine(q + "+" + y1 + "=" + program.Add(q, y1));
Console.WriteLine(q + "+" + w + "+" + e + "=" + program.Add(q, w, e));
Console.ReadLine();

}
}
}

posted @ 2017-06-15 14:55  诗为马  阅读(183)  评论(0编辑  收藏  举报