You can optimize the code by using the ternary operator, pass a parameter to this function it will compare the salary with the given value and if the condition satisfied It will print the value before the colon and if not satisfied it will print the value after colon.
Ternary Operator (?:)
condition ? condition satisfied : Condition not satisfied
string TernaryOperatorUsage(int Salary)
{
return salary >= 5000 ? "Congratulations! You are eligible for a pay hike." :
"Sorry! You're not eligible for a pay hike.";
}
The above example illustrates the use of ternary operator in your code.
Ternary Operator (?:)
condition ? condition satisfied : Condition not satisfied
string TernaryOperatorUsage(int Salary)
{
return salary >= 5000 ? "Congratulations! You are eligible for a pay hike." :
"Sorry! You're not eligible for a pay hike.";
}
The above example illustrates the use of ternary operator in your code.
Comments
Post a Comment