与控制台应用程序有关 [英] related to console applications

查看:73
本文介绍了与控制台应用程序有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#控制台程序

I have a console program of C#

class Program
    {
    public int equi(int[] A)
    {
        long sum = 0;
        int i = 0;
        for (i = 0; i < A.Length; i++)
        {
            sum += (long)A[i];
        }

.......


我遇到类似
的错误


I am having error like

报价:

.exe文件丢失或纠正了您的路径名

.exe file is missing or correct your path name


我是否需要添加


Do I need to add

static void Main(string[] args)
{}

推荐答案

您的控制台应用程序需要知道从哪里开始.这是通过称为Main()的特殊方法完成的.您必须在您的应用程序中使用此方法,否则该方法将无法运行,因为它不知道要执行什么.

这是有关如何使用Main()的更多信息:

http://www.dotnetperls.com/main [
Your console application needs to know where to start. This is done via a special method called Main(). You must have this method in your application or it will not run because it won''t know what to execute.

Here is some more information about how to use Main():

http://www.dotnetperls.com/main[^]


Main方法是C#控制台应用程序或Windows应用程序的入口点. (库和服务不需要Main方法作为入口点.)启动应用程序时,Main方法是第一个被调用的方法.

C#程序中只能有一个入口点.如果有一个以上的类具有Main方法,则必须使用/main编译器选项编译程序,以指定将哪个Main方法用作入口点.

在MSDN上了解有关Main() 的更多信息:

http://msdn.microsoft.com/en-us/library/acy3edy3.aspx [ ^ ]
The Main method is the entry point of a C# console application or windows application. (Libraries and services do not require a Main method as an entry point.). When the application is started, the Main method is the first method that is invoked.

There can only be one entry point in a C# program. If you have more than one class that has a Main method, you must compile your program with the /main compiler option to specify which Main method to use as the entry point.

Read more about Main() at MSDN:

http://msdn.microsoft.com/en-us/library/acy3edy3.aspx[^]


对Manas的正确答案的补充:

我只能添加在Visual Studio下,可以使用项目属性"页的第一个属性"选项卡名称应用程序"下的选项来设置选项(选择带有入口点的类).设置此选项的控件称为启动对象".

Main方法应该是对入口点有效的签名之一的静态方法.解释如下:
http://en.wikipedia.org/wiki/Main_function#C.23 [ ^ ].

如果有多种方法可以视为入口点,则应使用选项启动对象"来解决这种歧义.

—SA
A minor addition to the correct answer by Manas:

I can only add that under Visual Studio, one can setup an option (selection of a class with an entry point) using project Properties page, under the first Properties tab name "Application". The control to set up this option is called "Startup object".

The Main method should be a static method of one of the signatures valid for an entry point. This is explained here:
http://en.wikipedia.org/wiki/Main_function#C.23[^].

If there is more than one method which could be considered as an entry point, the option "Startup object" should be used to resolve this ambiguity.

—SA


这篇关于与控制台应用程序有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆