using System;
class Test
{
public static int max(int x, int y)
{
if (x > y)
return x;
else
return y;
}
static public void Main()
{
Console.WriteLine("the max of 6 and 8 is:{0}", max (6,8));
}
}
存在的问题 1 max是个方法,你这里把它当成了一个类来创建对象,
2 静态方法只能调用静态方法,所以要在max方法前面声明其为静态
class Test
{
// max 是一个方法,而且要在 static 型的main方法中被调用,因此也要加上 static 关键字
public static int max(int x, int y)
{
if (x > y)
return x;
else
return y;
}
static void Main()
{
Console.WriteLine("the max of 6 and 8 is:{0}", max(6, 8)); //直接调用max方法
}
}
天啊,直接改成 int n = max(6,8);
就行了。
或者直接用
Console.WriteLine("the max of 6 and 8 is:{0}", max(6,8));
这一句就够了。