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

后端 未结 7 1428
说谎
说谎 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:57

    To aid readibility you could extract the Substring out into a variable and then test that:

    var partitionKeyBits = model.PartitionKey.Substring(2, 2);
    
    if (partitionKeyBits == "05" || partitionKeyBits == "06") {
    
    }
    

    But otherwise that is about it.

    0 讨论(0)
提交回复
热议问题