Click here to Skip to main content
16,020,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I convert this if condition to a LINQ statment, or using a ternary condition

C#
if (MenuEnabled == false)
   {
       _parentForm.CheckMenu(false);
   }
else if (MenuEnabled == true)
   { 
       _parentForm.CheckMenu(true);
   }


What I have tried:

nothing successful that worked as intended
Posted
Updated 16-Mar-16 23:50pm
Comments
[no name] 17-Mar-16 5:49am    
Why do you need above if-else condition to LINQ query. I believe that it not needed LINQ in this case. Before you want to LINQ just understand why do we use LINQ, not like to convert if-else to LINQ.

LINQ (Language Integrated Query) is a Microsoft programming model and methodology that essentially adds formal query capabilities into Microsoft .NET-based programming languages. Means it is mostly used in querying purpose like fetch largest value from an array.

1 solution

You don't need LINQ or a ternary operator. All you need is
C#
_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)
C#
if (MenuEnabled)
and (for == false)
C#
if (!MenuEnabled)


Also you don't need the if ... else if with bools - they can only be true or false so there is no need for the second if
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900