Combine return and switch

后端 未结 12 2069
长情又很酷
长情又很酷 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条回答
  •  梦如初夏
    2021-02-03 22:49

    I've created a Nuget package (FluentSwitch) that should do what you want. So you can do the following:

    var result = myValue.Switch()
        .When(1, "lalala")
        .When(2, "blalbla")
        .When(3, "lolollo")
        .Else("default")
        .Value();
    

提交回复
热议问题