Сер*_*гей 10 .net c# powershell
命令
dotnet myapp.dll -- [4, 3, 2]
抛出异常System.FormatException: Input string was not in a correct format
。我不知道语法。我应该如何正确传递参数?我用的是powershell。
Moe*_*ald 10
using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(string.Join('-', args));
}
}
}
Run Code Online (Sandbox Code Playgroud)
通过 Powershell 6 调用它:
dotnet .\ConsoleApp3.dll "[1,2,3]"
Run Code Online (Sandbox Code Playgroud)
输出:
[1,2,3]
Run Code Online (Sandbox Code Playgroud)
在上面的调用中,您的方法将作为单个字符串Main
接收,您必须在代码中解析/拆分它。[1,2,3]
如果您希望数组反映在string[]
数组中Main
,可以使用 PowerShell 数组:
dotnet .\ConsoleApp3.dll @(1,2,3)
Run Code Online (Sandbox Code Playgroud)
输出:
1-2-3
Run Code Online (Sandbox Code Playgroud)
这里 PowerShell 数组@(1,2,3)
被转换为string[]
-array。因此,PowerShell 数组的每个项目都被注入到该string[]
数组中。
PowerShell 5.1 上的行为相同。
归档时间: |
|
查看次数: |
6970 次 |
最近记录: |