控制台应用程序的参数,参数如何传递到Main方法 [英] Console app arguments, how arguments are passed to Main method

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

问题描述

这是从C#初学者的问题。 当我创建控制台应用程序我得到的主要方法,参数的args 作为数组的字符串。 我不知道如何调用此方法通过系统,以及如何的args传递到Main方法。也许有人能解释一下吗?是主要方法重写某种控制台类的?

 命名空间ConsoleApplication1
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
        }
    }
}
 

解决方案

主要方法是应用程序的入口点。如果通过反汇编检出然后

 。方法私人hidebysig静态无效的主要(字串[] args)CIL管理
{
  。入口点
 

这是帮助在调用方法

这些参数传递说 C:\ AppName的ARG1 ARG2 ARG3

This would be question from c# beginner. When I create console application I get Main method with parameter args as array string. I do not understand how this method is called by system and how args are passed to the Main method. Maybe someone could explain? Is Main method are overridden of some kind of console class?

namespace ConsoleApplication1
{
    class Program
    {    
        static void Main(string[] args)
        {    
        }
    }
}

解决方案

The Main method is the Entry point of your application. If you checkout via ildasm then

.method private hidebysig static void  Main(string[] args) cil managed
{
  .entrypoint

This is what helps in calling the method

The arguments are passed as say C:\AppName arg1 arg2 arg3

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

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