- 1

Explain conditional operator With suitable example

31st Mar 2017, 9:15 AM
vishal kalbande
vishal kalbande - avatar
2 Respostas
+ 1
In C#, int firstNumber = 1; int secondNumber = 2; if (firstNumber > secondNumber) { Console.WriteLine(firstNumber); } else { Console.WriteLine(secondNumber); } --------------------------------------------------- if conditional operator checks the statement that you pass as the parameters. if () --> it will return either true or false it is like. bool if(arguments) { return bool; } so if you insert any parameters in if method arguments, it always return either true or false, if the condition is true, it processes the condition. In the example, firstNumber is 1. secondNumber is 2. // This will check whether the parameters you pass are true or false if(firstNumber > secondNumber) { // This will check whether firstNumber is greater than secondNumber // 1 > 2, 1 is not greater than 2, so it returns the value of false. // so it goes to next line else // else always print out if all the previous functions are not taking the parameters and process. // so in the end, it goes for else statement. } else { // you just print what you want if the previous conditions are not met. }
31st Mar 2017, 9:33 AM
Yhal Htet Aung
Yhal Htet Aung - avatar
0
Ok, you are new. - Pick and enroll on c++ course on app. - Star to learn and enjoy the travel
31st Mar 2017, 9:35 AM
nextco
nextco - avatar