我正在尝试在Windows Terminal中打开WSL (Ubuntu) 选项卡,然后使用 WSL 在该选项卡中运行命令。我为此使用以下 PowerShell 命令:
wt new-tab -p "WSL (Ubuntu)" wsl echo "hallo"
Run Code Online (Sandbox Code Playgroud)
问题是,echo运行后,选项卡立即关闭。有办法让它保持打开状态吗?
powershell windows-subsystem-for-linux windows-terminal wsl-2
我有这个代码,这LongMethodWithResult是一个需要很长时间才能运行的方法:
object o = LongMethodWithResult() == someVal ? LongMethodWithResult() : someOtherResult;
Run Code Online (Sandbox Code Playgroud)
现在这个LongMethodWithResult方法被评估了两次,不是吗?
我知道我可以编写一个方法,使用变量来存储long方法的结果,如下所示:
public static object ConciseConditionalOperator(object a, object b, object c)
{
return a == b ? a : c;
}
Run Code Online (Sandbox Code Playgroud)
但我会对是否有最好的方法,或者C#或.NET提供的某些功能感兴趣.
欢迎任何想法!