在這裏,我們將了解 Environment 類的 GetCommandLineArgs() 方法。此方法用於獲取 命令行 參數。此方法返回一個字符串數組,其中包含在命令行上傳遞的參數。
用法:
string [] Environment.GetCommandLineArgs();
參數:
這不接受任何參數。
返回值:
此方法返回一個字符串數組,其中包含在命令行上傳遞的參數。
異常:
- System.NotSupportedException
程序:
下麵給出了演示使用 Environment 類的 GetCommandLineArgs() 方法的源代碼。給定的程序已成功編譯並執行。
using System;
class Sample
{
//Entry point of Program
static public void Main()
{
string[] cmdArg;
cmdArg = Environment.GetCommandLineArgs();
Console.WriteLine("Command Line Arguments:");
foreach (string arg in cmdArg)
{
Console.WriteLine("\t"+arg);
}
}
}
在這裏,我們使用命令提示符執行上述程序以查看在命令行上傳遞的所有參數。
輸出:
D:\>Program.exe 123 ABCD Command Line Arguments: Program.exe 123 ABCD
相關用法
- C# Environment GetEnvironmentVariable()用法及代碼示例
- C# Environment FailFast()用法及代碼示例
- C# Environment Exit()用法及代碼示例
- C# Enum Equals()用法及代碼示例
- C# Enum CompareTo()用法及代碼示例
- C# Enum ToObject()用法及代碼示例
- C# Enum Format()用法及代碼示例
- C# Enum Parse()用法及代碼示例
- C# Decimal.FromOACurrency()用法及代碼示例
- C# Int32.CompareTo用法及代碼示例
- C# File.WriteAllLines(String, IEnumerable<String>)用法及代碼示例
- C# Type.GetTypeHandle()用法及代碼示例
- C# Uri.IsBaseOf()用法及代碼示例
- C# String.ToUpperInvariant用法及代碼示例
- C# File.Copy(String, String, Boolean)用法及代碼示例
- C# Uri.IsHexEncoding()用法及代碼示例
- C# Char.TryParse()用法及代碼示例
- C# Math Cosh()用法及代碼示例
- C# Int64.Equals用法及代碼示例
- C# Convert.ToInt16(String, IFormatProvider)用法及代碼示例
注:本文由純淨天空篩選整理自 C# program to demonstrate the use of GetCommandLineArgs() method of Environment class。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。