In C#, what is the simplest way to calculate "trend" given a current and previous status? -


i have variable show rag status (red, amber, green) on project

var previousstatus = "r" var currentstatus = "a" 

and trying calculate "trend" sometihng like

  var trend = calculatetrend(previous, current) 

i trying find more elegant solution than

            if (prev == current)             return "stable";          if (prev == "r" && (current == "g" ||current == "a"))               return "improving";          if (prev == "g" && (current == "r" ||current == "a"))               return "declining";         if (prev == "a" && current == "g")             return "improving";         if (prev == "a" && current == "r")             return "declining"; 

any suggestion on "cleaner" solution.

create enum integer value each status.

public enum status {     red = 1,     amber = 2,     green = 3            } 

then use int.compareto method.

switch(previous.compareto(current)) {     case -1:         return "improving";      case 0:         return "stable";      case 1:         return "declining"; } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -