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

后端 未结 7 1433
说谎
说谎 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.

提交回复
热议问题