c# - Switch case with Boolean -


i trying create prefix text value project. using switch case that. when user select relevant radio button should give prefix value.

what should give after "switch ()"

the value coming user selection boolean value. output string.

any help..

 public string officepostfix()   {    string postfix = null;      switch (...)         {             case sheetmgrform.goldcoast = true:                 postfix = "qld";                 break;             case sheetmgrform.melbourne = true:                 postfix = "mel";                 break;             case sheetmgrform.sydney = true:                 postfix = "syd";                 break;             case sheetmgrform.brisbane = true:                 postfix = "bis";                 break;         }         return postfix;      } 

that's not how switch works. can't put arbitrary boolean expression in each case (assuming mean == , not =, btw).

you need use set of if-else blocks, like:

if (sheetmgrform.goldcoast) {     postfix = "qld"; } else if (sheetmgrform.melbourne) {     postfix = "mel"; } else if ...... 

however, looks design use rework. having separate booleans clumsy.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -