我在看一个电子书,上面的有个关于方法的代码
using System;
  class Test 
 {
   public int max(int x,int y){
     if(x>y)
       return x;
       else
       return y;     }
public void Main(){
Console.WriteLine("the max of 6 and 8 is:{0}",max(6,8));
   }
   }
我写出来用csc编译提示
C:\>csc max.cs
Microsoft (R) Visual C# .NET 编译器版本 7.10.3052.4
用于 Microsoft (R) .NET Framework 版本 1.1.4322
版权所有 (C) Microsoft Corporation 2001-2002。保留所有权利。error CS5001: 程序“c:\max.exe”未定义入口点
请问是什么原因
{0}表示什么意思,我在
string name=sunange;
Console.WriteLine("学习:{1}",name)
这样写为什么会出错,谢谢:)

解决方案 »

  1.   

    public static void Main(...)
      

  2.   

    C:\>csc max.cs
    Microsoft (R) Visual C# .NET 编译器版本 7.10.3052.4
    用于 Microsoft (R) .NET Framework 版本 1.1.4322
    版权所有 (C) Microsoft Corporation 2001-2002。保留所有权利。max.cs(14,47): error CS0120: 非静态的字段、方法或属性“Test.max(int,
            int)”要求对象引用
      

  3.   

    public static int max(int x,int y)
    {
         if(x>y)
           return x;
         else
           return y;}
      

  4.   

    static void Main(string[] args)  //定义入口点
    {
    }{0}表示第一个参数string name=sunange;
    Console.WriteLine("学习:{1}",name)你这样写都没有第二个参数,当然会报错拉
      

  5.   

    using System;
     class Test 
     {
       public static int max(int x,int y){
         if(x>y)
           return x;
           else
           return y;     }
    public static void Main(){
    Console.WriteLine("the max of 6 and 8 is:{0}",max(6,8));
       }
       }
      

  6.   

    using System;
     class Test 
     {
       public  int max(int x,int y){
         if(x>y)
           return x;
           else
           return y;     }
    public static void Main(){class1 c1 = new Class1();
    Console.WriteLine("the max of 6 and 8 is:{0}",c1.max(6,8));
       }
       }
      

  7.   

    main 函数 需要是 static 的,作为程序开始执行的地方