如果你想通过命令行传递参数,那么在C#中使用命令行参数 -
当我们在C#中创建程序时,使用static void main,我们可以看到其中的参数。
class HelloWorld { static void Main(string[] args) { /* my first program in C# */ Console.WriteLine("Hello World"); Console.ReadKey(); }
string[] args 是一个变量,它包含从命令行传递的所有值,如上所示。
现在要打印这些参数,假设我们有一个参数“One” -
Console.WriteLine("Length of the arguments: "+args.Length); Console.WriteLine("Arguments:"); foreach (Object obj in args) { Console.WriteLine(obj); }
上面将打印 -
Length of the arguments: 1 Arguments: One
以上就是C# 中的命令行参数的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号