ANSWERSGO.com

Added new notification system!, Receive a notification alerting you about actions on your questions and answers. Report any bug in meta Thanks



1

Answers

 

0

Stars

Better way to write IF conditions

Asked By : Ahmed Ali ♦ C#

I have an object, lets say serviceData that has a nullable boolean property, lets call it Potato. I want to create a string that says yes if Potato is true and no if Potato is false.

I wrote 

string potato= "";
  if (serviceData.Potato == true)
  {
    potato = "Yes";
  }
  if (serviceData.Potato == false)
  {
    potato = "No";
  }

Any better way to do this?




1 Answers



1

Stars

  

var potato= (serviceData.Potato == true ? 'Yes' : 'No');

~Arsalan

.


- GeekyCoder17 2020-07-23 09:40:35

Add Comment

 

Thanks it worked! - Ahmed Ali ♦




Question Comments:

Feel free to discuss about question, here!


Any suggestions? - Ahmed Ali ♦