以下是我尝试过的内容和发生的情况的记录。
我正在寻找如何调用特定的重载以及为什么以下不起作用的解释。如果您的回答是“您应该改用此命令行开关”或“调用两次”,请理解我不接受您的回答。
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);
可以同时调用这两个,还是只调用一个?显然,在这种特定情况下,很难区分。