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

后端 未结 13 1752
谎友^
谎友^ 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:19

    the two options are not equivalent. A part from a bug in the second snippet (it should read if(string.IsNullOrEmpty(value)), it will handle two cases, null and empty strings, whereas the ?? operator only handles nulls.

    A part from that it's way more readable. I side with your boss.

提交回复
热议问题