
Main() 方法是入口点 -
static void Main(string[] args)
参数数组args用于设置参数 -
string[] args)
如果添加两个参数,它将设置以下内容 -
var args = new string[] {"arg1","arg2”}这里是演示代码 -
using System;
namespace Demo {
class HelloWorld {
// args for command line
static void Main(string[] args) {
Console.WriteLine("Welcome here!");
Console.ReadKey();
}
}
}使用命令行而不是 Visual Studio IDE 编译 C# 程序 -
打开文本编辑器并添加上述代码.
将文件另存为 helloworld.cs
打开命令提示符工具并转到保存文件的目录文件。
输入 csc helloworld.cs 并按 Enter 编译您的代码。
如果您的代码中没有错误代码后,命令提示符会将您带到下一行并生成 helloworld.exe 可执行文件。
键入 helloworld 来执行您的程序。
您可以看到输出 Hello World 打印在屏幕上。
以上就是C# 的 main 方法中如何传递命令行参数?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号