C#编程基础全解析
1. 命令行参数处理与编译
在C#中,我们可以编写处理命令行参数的程序。以下是一个示例代码:
using System;
namespace Wrox.ProCSharp.Basics
{
class ArgsExample
{
public static int Main(string[] args)
{
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine(args[i]);
}
return 0;
}
}
}
编译这个程序后,运行时可以在程序名后传入参数,例如:
ArgsExample /a /b /c
输出结果为:
/a
/b
/c
在编译C#文件时,除了常见的控制台应用程序编译,还有其他类型的应用程序编译需求。下面是一些重要的编译选项:
| 选项 | 输出 |
| ---- | ---- |
| /t:exe | 控制台应用程序(默认) |
| /t:library | 带清单的类库 |
| /t:module