2013-12-09 64 views
1

我试图创建一个控制台应用程序来实现正常的堆栈操作。但是,当我试图通过主方法调用Push和Pop方法时。我收到以下错误。然后我创建了一个单独的类“堆栈”并粘贴该类中的所有代码。现在,即使当我尝试创建类STACK的实例,然后从主方法引用Push和Pop方法时,我仍然收到错误。Namespace.exe不包含适用于入口点的静态Main方法

StackImplementation.exe不包含适合的入口点的静态主方法

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace StackImplementation 
{ 

    class stack 
    { 
     int[] a=new int[5]; 
     int top = -1; 

    public void push(int value) 
    { 
     if (top == 4) 
     { 
      Console.WriteLine("The List is Full"); 
     } 
     else 
     top = top + 1; 
     a[top] = value; 
    } 

    public void pop() 
    { 
     if (top == -1) 
     { 
      Console.WriteLine("The List is Empty"); 
     } 

     else 
      top = top - 1; 
    } 

    public void display() 
    { 
     int i; 

     if (top == -1) 
      Console.WriteLine("Nothing to Display"); 
     else  
     for (i = 1; i < top; i++) 
     { 
      Console.WriteLine("The List is {0}",a[i]); 
     } 
    } 
    } 

    class Program 
    { 
     static int main() 
     { 
      stack stc = new stack(); 
      int choice, value; 
      do 
      { 

       Console.WriteLine("/n 1.Push"); 
       Console.WriteLine("/n 2.Pop"); 
       Console.WriteLine("/n 3.Display"); 
       Console.WriteLine("Enter Your Choice"); 
       choice = Convert.ToInt32(Console.ReadLine()); 
       if (choice == 1) 
       { 
        Console.WriteLine("Enter the value to be inserted"); 
        value = Convert.ToInt32(Console.ReadLine()); 
        stc.push(value); 
       } 

       if (choice == 2) 
       { 
        stc.pop(); 
       } 

       if (choice == 3) 
       { 
        stc.display(); 
       } 
      } while (choice != 0); 
      Console.ReadKey(); 
      return 0; 
     } 
    } 
} 
+0

由于lazyberezovsky回答任何程序需要一个静态的主要方法。由于C#区分大小写,因此您的主要方法没有正确命名。将其命名为'Main'。 –

回答

1

C#区分大小写。

main重命名为Main,以便编译器看到正确的入口点。

+0

问题解决了!谢谢!! – Aron88

0

任何C#程序应具有静态方法Main其中开始执行。见Main() and Other Methods文章:

每一个C#应用程序必须包含一个Main方法指定 其中程序执行开始。 在C#中,Main是大写,而 Java使用小写main。

所以,只是让main方法名称帕斯卡案(大写)。实际上,这个命名约定适用于C#中的类型名称和所有其他方法。

+0

问题解决了谢谢! – Aron88

0

改变你的计划主要以:

static int Main() 

通知的情况下更改,C#是区分大小写的。

+1

不需要使其成为“公共”。 –

相关问题