本文實例講述了C#訪問命令行的兩種方法。分享給大家供大家參考。具體如下:
方法1:
// 參數:A B Cusing System;public class CommandLine{ public static void Main(string[] args) { // Length 屬性用于獲取數組的長度。 // 注意,Length 是只讀屬性: 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]); } }}
方法2:
// 參數:John Paul Maryusing 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); } }}
希望本文所述對大家的C#程序設計有所幫助。
新聞熱點
疑難解答