使用系统; 使用System.Collections.Generic; 使用System.Text;
namespace MyConApp
{
class Program
{
static void Main(string args)
{
string tmpString;
tmpString = args;
Console.WriteLine("Hello" + tmpString);
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么下面的表达式显示编译错误消息"不包含适用于入口点的静态'Main'方法"
namespace MyConApp
{
class Program
{
static void Main(string args)
{
string tmpString;
tmpString = args;
Console.WriteLine("Hello" + tmpString);
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
在您提供的代码中,问题在于“主”入口点期望在调用程序时从系统传递一个字符串数组(此数组可以为null,没有元素)
纠正改变
static void Main(string args)
Run Code Online (Sandbox Code Playgroud)
至
static void Main(string[] args)
Run Code Online (Sandbox Code Playgroud)
如果您声明“ void”或“ int”以外的任何类型的“ Main”,则可能会遇到相同的错误
因此,“ Main”方法的签名必须始终是
static // ie not dynamic, reference to method must exist
public // ie be accessible from the framework invoker
Main // is the name that the framework invoker will call
string[] <aName> // can be ommited discarding CLI parameters
* is the command line parameters space break(ed)
Run Code Online (Sandbox Code Playgroud)
从MS(...),Main方法可以使用参数,在这种情况下,它采用以下形式之一:
static int Main(string[] args)
static void Main(string[] args)
Run Code Online (Sandbox Code Playgroud)