使用string [] args从命令行调用控制台应用程序 [英] Calling a console app from the command line with string[] args

查看:58
本文介绍了使用string [] args从命令行调用控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET Console应用程序(非常简单)。入口点采用了臭名昭著的string [] args参数。这是否意味着我可以从命令行调用此应用,并将单个字符串作为参数传递?如果是,怎么办?

I have a .NET Console app (very simple). The entry point takes the infamous string[] args argument. Does this mean that from a command line, I could call this app and pass in a single string as a parameter? If so, how?

推荐答案

是的, string [] args 来自命令行。第零个元素是第一个参数,依此类推。请注意,与C或C ++不同, args [0] 不包含应用程序名称。

Yes, the string[] args is from the command line. The zeroth element is the first argument and so on. Please note unlike C or C++, args[0] doesn't contain the application name.

因此,如果您做:

application.exe arg1 arg2 arg3

然后:

args[0] = arg1
args[1] = arg2
args[2] = arg3

如果仅传递一个参数,则可用 args [0]

If you pass only one argument, that is available as args[0].

这篇关于使用string [] args从命令行调用控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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