Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello
I have status variable which has three valuse 1,2,3
1.Approved
2.Reject
3.Pending
I wand to use nested ternary operator.how can i use it?
Posted

Try:
C#
string result = status == 1 ? "Approved" : status == 2 ? "Reject" : "Pending";

However, I would use a switch instead:
C#
switch (status)
   {
   case 1: result = "Approved"; break;
   case 2: result = "Reject"; break;
   case 3: result = "Pending"; break;
   default: result = "ERROR"; break;
   }
 
Share this answer
 
Status = (y.Status == 1) ? "Approved" : ((y.Status == 2) ? "Reject" : "Pending")
 
Share this answer
 

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