有其他开关吗?

new*_*mer -1 powershell

switch在 PowerShell 中就像一个不太复杂的if elseif语句,但else不起作用。还有什么我可以做的吗?

switch ("test") {
  "1" {"2"}
  "2" {"1"}
} else {"other"}
Run Code Online (Sandbox Code Playgroud)

给出错误

else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:4 char:3
+ } else {"other"}
+   ~~~~
    + CategoryInfo          : ObjectNotFound: (else:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Run Code Online (Sandbox Code Playgroud)

小智 7

开关的 else 是default选项:

switch ("test") {
  "1" {"2"}
  "2" {"1"}
  Default {"other"}
}
Run Code Online (Sandbox Code Playgroud)