C# 中的命令行参数
如果你想通过命令行传递参数,请在 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
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 程序设计
C++
C#
MongoDB
MySQL
Javascript
PHP