In c# can the conditional operator replace the if-else statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

In c# can the conditional operator replace the if-else statement

29th Sep 2020, 10:15 AM
KingZord
KingZord - avatar
4 Answers
+ 4
I am wondering how would we use conditional operator in place of if else ? a==b won't do anything alone You need an if to check , if(a==b) then do something likewise a&&b does nothing ,I mean it will definitely give output as true or false but if you want to do something based on that you still need to use if else , Am I wrong ? Or can anyone give an example!
29th Sep 2020, 10:33 AM
Abhay
Abhay - avatar
+ 3
😐😐 Geez!
29th Sep 2020, 10:41 AM
hossein B
hossein B - avatar
0
Nasif Rahman in what situation can I not use the conditional operator in place of the if-else conditional operator
29th Sep 2020, 10:34 AM
KingZord
KingZord - avatar
0
A ternary operator ? : is an irregular exception in this case, because other than ternary operator, AFAIK there is no other logical operator which allows a way for simulating what an if-else block does.
29th Sep 2020, 2:28 PM
Ipang