gpt4 book ai didi

c# - 我该如何缩短 If else

转载 作者:太空狗 更新时间:2023-10-30 00:18:43 25 4
gpt4 key购买 nike

我的代码看起来像

private bool IsUserAditya(string username)
{
return username == "Aditya"? true : false;
}

我可以进一步缩短吗?

我将不胜感激。

最佳答案

Can I shorten it further?

有一点

返回用户名 == "Aditya";

C# 中的任何比较都会返回一个 bool,因此无需使用条件运算符。

关于c# - 我该如何缩短 If else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31918410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com