c# 3.0 - Getting Error: return statement is missing in switch statement -


i thought switch case written correctly got error:

return statement missing in last bracket.

please find below code:

    public  string  geturl(string code )        {         switch (code)          {            case  "1":                return "#";           case "2":               return "#";           case "3":                return "#";           case "4":               return "#";           case "5":                return "#";           case "6":                return "#";           case "7":                return "#";           }      } 

thanks in advance

what missing default case. string should function return if none of cases mentioned occur.

e.g. pass "unknown" method geturl.

so add default case , things should work fine.

the code should like

    public  string  geturl(string code )        {         switch (code)          {            case  "1":                return "#";           case "2":               return "#";           case "3":                return "#";           case "4":               return "#";           case "5":                return "#";           case "6":                return "#";           case "7":                return "#";           default:               return "unknown case occured!";          }      } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -