Should I Throw ArgumentNullException if a string is blank?

前端 未结 7 1735
独厮守ぢ
独厮守ぢ 2020-12-14 00:11

I working on a method that does something given a string parameter. A valid value for the string parameter is anything other than null or string.Empty. So my code looks li

7条回答
  •  醉酒成梦
    2020-12-14 00:24

    You should throw an ArgumentException if an empty string is not an accepted input for your method. It may be very confusing to clients if you throw an ArgumentNullException while they didn't provide a null argument.

    It is simply another use case. You may also have methods that do not accept null input values but that do accept empty strings. It's important to be consistent across your entire application.

提交回复
热议问题