将if条件转换为linq [英] Convert an if condition to linq
问题描述
如何将此if条件转换为LINQ语句,或使用三元条件
if (MenuEnabled == false )
{
_parentForm.CheckMenu(假跨度>);
}
else if (MenuEnabled == true )
{
_parentForm.CheckMenu( true );
}
我的尝试:
没有成功按预期工作
您不需要LINQ或三元运算符。您只需要
_ parentForm.CheckMenu(MenuEnabled);
以上评论是真实的,并回答了你的问题,但我担心你写这些陈述的方式 - 现在也可以在你养成坏习惯之前先了解这一点:)
您不需要使用== false
或== true
使用布尔值时。只需使用(for == true)if (MenuEnabled)
和(for == false)
if (!MenuEnabled)
还有你不需要if ... else
with bools - 它们只能是true或false所以不需要第二个如果
How can I convert this if condition to a LINQ statment, or using a ternary condition
if (MenuEnabled == false)
{
_parentForm.CheckMenu(false);
}
else if (MenuEnabled == true)
{
_parentForm.CheckMenu(true);
}
What I have tried:
nothing successful that worked as intended
You don't need LINQ or a ternary operator. All you need is
_parentForm.CheckMenu(MenuEnabled);
[Edit]
The above comment is true and answers your question but I am concerned about the way you have written these statements - may as well learn this now before you get into bad habits :)
You don't need to use== false
or== true
when using Booleans. Just use (for == true)if (MenuEnabled)
and (for == false)
if (!MenuEnabled)
Also you don't need theif ... else if
with bools - they can only be true or false so there is no need for the secondif
这篇关于将if条件转换为linq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!