Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I change this condition to that I want

Tags:

c#

asp.net

I have a condition with two value. if the condition equal to 0 it return Absent and if equal to 1 it returns present. now I want to add the third value into my condition. if the condition equal to 3 it returns Unacceptable absent.

this is my conditions with two value:

(status >= 1 ? "Present" : "Absent")

how can I change the condition?

like image 395
dorsa Avatar asked Jun 13 '19 06:06

dorsa


Video Answer


1 Answers

Use a lookup dictionary.

//Initialized once in your program
var lookup = new Dictionary<int,string>
{
    { 0, "Absent"},
    { 1, "Present"},
    { 3, "Unacceptably Absent" }
};

//Call this whenever you need to convert a status code to a string
var description = lookup[status];
like image 120
John Wu Avatar answered Nov 15 '22 07:11

John Wu