![](/img/trans.png)
[英]How to pass multi-valued arguments containing commas to a property in dotnet command line tool?
[英]How to pass arguments in command line using dotnet?
命令dotnet myapp.dll -- [4, 3, 2]
引發異常System.FormatException: Input string was not in a correct format
。 我不知道語法。 我應該如何正確傳遞參數? 我使用Powershell。
using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(string.Join('-', args));
}
}
}
通過Powershell 6調用它:
dotnet .\ConsoleApp3.dll "[1,2,3]"
輸出:
[1,2,3]
在上面的調用中, Main
將以單個字符串的形式接收[1,2,3]
,並且您必須在代碼中對其進行解析/拆分。
如果要在Main
的string[]
-array中反映一個數組,則可以使用PowerShell數組:
dotnet .\ConsoleApp3.dll @(1,2,3)
輸出:
1-2-3
在這里,PowerShell數組@(1,2,3)
被強制轉換為string[]
-array。 因此,PowerShell數組的每一項都注入到string[]
數組中。
行為在PowerShell 5.1上相同。
希望能有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.