一个爱好编程的程序员

导航

C# 程序员参考--命令行参数教程

示例 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] );

        }

    }

}

输出

        使用如下所示的一些参数运行程序:cmdline1 A B C.

         输出将为:

Number of command line parameters = 3

Arg[0] = [A]

Arg[1] = [B]

Arg[2] = [C]

posted on 2006-03-15 15:44  罗建平  阅读(275)  评论(0编辑  收藏  举报