以下是我尝试过的内容和发生的情况的记录。
我正在寻找如何调用特定重载以及解释为什么以下内容不起作用。如果您的答案是“您应该使用此命令行开关”或“调用两次”,请理解我不接受您的答案。
PS C:\> [System.IO.Path]::Combine("C:\", "foo")
C:\foo
PS C:\> [System.IO.Path]::Combine("C:\", "foo", "bar")
Cannot find an overload for "Combine" and the argument count: "3".
At line:1 char:26
+ [System.IO.Path]::Combine <<<< ("C:\", "foo", "bar")
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
PS C:\> [System.IO.Path]::Combine(, "C:\", "foo", "bar")
Missing ')' in method call.
At line:1 char:27
+ [System.IO.Path]::Combine( <<<< , "C:\", "foo", "bar")
+ CategoryInfo : ParserError: (CloseParenToken:TokenId) [], Paren
tContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndParenthesisInMethodCall
PS C:\> [System.IO.Path]::Combine($("C:\", "foo", "bar"))
Cannot find an overload for "Combine" and the argument count: "1".
At line:1 char:26
+ [System.IO.Path]::Combine <<<< ($("C:\", "foo", "bar"))
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
这就是我在 c# 中所做的,它有效:
var foobar = Path.Combine(@"C:\", "foo", "bar");
Console.WriteLine(foobar);
什么 Powershell 将调用该特定重载? Path.Combine 具有以下两者:
public static string Combine (string path1, string path2, string path3);
public static string Combine (params string[] paths);
是否可以同时调用这两个,或者只调用其中一个?显然,在这种具体情况下,很难区分其中的差异。