关于C#命令行参数教程
来源:互联网 发布:饥荒联机版修改数据 编辑:程序博客网 时间:2024/06/05 23:45
本教程展示如何访问命令行以及访问命令行参数数组的两种方法。
教程
下面的示例展示使用传递给应用程序的命令行参数的两种不同方法。
示例 1
本示例演示如何输出命令行参数。
// cmdline1.cs
// arguments: A B C
输出
使用如下所示的一些参数运行程序:cmdline1 A B C。
输出将为:
Number of command line parameters = 3
Arg[0] = [A]
Arg[1] =
Arg[2] = [C]
示例 2
循环访问数组的另一种方法是使用 foreach 语句,如本示例所示。foreach 语句可用于循环访问数组或“.NET Framework”集合类。它提供了一种简单的方法来循环访问集合。
// cmdline2.cs
// arguments: John Paul Mary
输出
使用如下所示的一些参数运行程序:cmdline2 John Paul Mary。
输出将为:
Number of command line parameters = 3
John
Paul
Mary
教程
下面的示例展示使用传递给应用程序的命令行参数的两种不同方法。
示例 1
本示例演示如何输出命令行参数。
// cmdline1.cs
// arguments: A B C
using System;
public class CommandLine
...{
public static void Main(string[] args)
...{
// The Length property is used to obtain the length of the array.
// Notice that Length is a read-only property:
Console.WriteLine("Number of command line parameters = {0}",
args.Length);
for(int i = 0; i < args.Length; i++)
...{
Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
}
}
}
public class CommandLine
...{
public static void Main(string[] args)
...{
// The Length property is used to obtain the length of the array.
// Notice that Length is a read-only property:
Console.WriteLine("Number of command line parameters = {0}",
args.Length);
for(int i = 0; i < args.Length; i++)
...{
Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
}
}
}
输出
使用如下所示的一些参数运行程序:cmdline1 A B C。
输出将为:
Number of command line parameters = 3
Arg[0] = [A]
Arg[1] =
Arg[2] = [C]
示例 2
循环访问数组的另一种方法是使用 foreach 语句,如本示例所示。foreach 语句可用于循环访问数组或“.NET Framework”集合类。它提供了一种简单的方法来循环访问集合。
// cmdline2.cs
// arguments: John Paul Mary
using System;
public class CommandLine2
...{
public static void Main(string[] args)
...{
Console.WriteLine("Number of command line parameters = {0}",
args.Length);
foreach(string s in args)
...{
Console.WriteLine(s);
}
}
}
public class CommandLine2
...{
public static void Main(string[] args)
...{
Console.WriteLine("Number of command line parameters = {0}",
args.Length);
foreach(string s in args)
...{
Console.WriteLine(s);
}
}
}
输出
使用如下所示的一些参数运行程序:cmdline2 John Paul Mary。
输出将为:
Number of command line parameters = 3
John
Paul
Mary
- 关于C#命令行参数教程
- C#系列教程——使用 foreach 访问命令行参数
- C#的命令行参数
- C# 接受命令行参数
- 关于c# 默认参数
- C# Main方法及命令行参数
- C# WPF 接收启动命令行参数
- 一个简单的C#命令行参数程序
- C#调用命令行返回参数方法
- 关于Main函数的命令行参数
- 关于ffmpeg命令行的ss参数
- 关于ffmpeg命令行的ss参数
- 关于命令行参数argv(《学习OpenCV》)
- 关于c语言命令行参数的问题
- [Oracle] SQL*Loader 详细使用教程(2)- 命令行参数
- WPF教程(十一)WPF中的命令行参数
- 命令行参数
- 命令行参数
- 在Access中创建表及如何指定字段类型
- Manning的新书 Ajax in Practice 发布了。
- 针对hibernate,jdbc,sql的思考
- 链路层(一)
- sql 日期函数详解
- 关于C#命令行参数教程
- Hacking swing: 一个JDBC表控件模型
- 部署和分发.NET应用程序的两种方法
- 使用FreeMarker生成Html静态文件
- 07年奋战长春亚冬会,08期待再战北京奥运会
- Constants in the Microsoft DAO 3.0 Object Library
- 离职了
- tabcontrol控件的tabPage的text内容显示成竖着的字体
- 数据库连接、设计以及备份技巧集锦