[英]How can I read this parameters inside my software? (c#)
我已經創建了.exe文件的快捷方式。
我想向'.exe'添加額外的參數。(快捷方式:Target屬性)
例
目標:
“ C:\\ Documents and Settings \\ dezigo \\ My Documents \\ c#programm \\ DirectoryScanner \\ DirectoryScanner \\ DirectoryScanner \\ bin \\ Debug \\ DirectoryScanner.exe” +額外的參數(例如method = 1)
如何在軟件中讀取此參數? (C#)
然后,當啟動.exe時
校驗
if(method == 1)
{
//do something
}
else
{
//do something
}
您可以使用Environment.CommandLine屬性來獲取運行可執行文件時傳遞的命令行,並對其進行解析以獲得參數。 參數還將在Main
方法中傳遞:
class Program
{
static void Main(string[] args)
{
// The args array will contain the arguments passed at the command line
// For example if the executable has been launched like:
// "DirectoryScanner.exe method=1"
// args[0] will contain "method=1"
}
}
您必須使用傳遞給主函數的args變量。
在這里您將找到詳細信息: http : //msdn.microsoft.com/zh-cn/library/bb251798.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.