Combine return and switch

后端 未结 12 2068
长情又很酷
长情又很酷 2021-02-03 22:15

How can I combine return and switch case statements?

I want something like

return switch(a)
       {
          case 1:\"lalala         


        
12条回答
  •  梦毁少年i
    2021-02-03 22:30

    I normally do it this way:

    var result = null;
    
    switch(a)
    {
        case 1:
            result = "lalala";
            break;
        case 2:
            result = "blalbla";
            break;
        case 3:
            result = "lolollo";
            break;
        default:
            result = "default";
            break;
    };
    
    return result;
    

提交回复
热议问题