我试图创建一个控制台应用程序来实现正常的堆栈操作。但是,当我试图通过主方法调用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;
}
}
}
由于lazyberezovsky回答任何程序需要一个静态的主要方法。由于C#区分大小写,因此您的主要方法没有正确命名。将其命名为'Main'。 –