Is there a simpler way to do this if statement in C#

后端 未结 7 1438
说谎
说谎 2021-01-21 03:05

I have the following:

if (model.PartitionKey.Substring(2, 2) == \"05\" || 
    model.PartitionKey.Substring(2, 2) == \"06\")

I have more like t

7条回答
  •  温柔的废话
    2021-01-21 03:46

    I'm surprised nobody offered switch as a possible alternative :)

    switch (model.PartitionKey.SubString(2,2)) {
      case "05":
      case "06":
        // do stuff
        break;
      // other cases
      default:
        // like an else
    }
    

    You can read more about it at MSDN

提交回复
热议问题