In your opinion what is more readable: ?? (operator) or use of if's

后端 未结 13 1722
谎友^
谎友^ 2021-01-21 07:05

I have a method that will receive a string, but before I can work with it, I have to convert it to int. Sometimes it can be null and I ha

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 07:17

    I think your best option is to do what your boss says, this one isn't worth it! That said, add a few spaces around yours and I like it better.

    int someValue = int.Parse(value ?? "0");
    

提交回复
热议问题