ArgumentException or ArgumentNullException for string parameters?

前端 未结 4 600
南旧
南旧 2020-12-14 06:52

Far as best practices are concerned, which is better:

public void SomeMethod(string str) 
{
    if(string.IsNullOrEmpty(str))
    {
        throw new Argumen         


        
4条回答
  •  清歌不尽
    2020-12-14 07:25

    I would suggest using the first one. If your method doesn't expects null or empty string it really doesn't matter if null or empty was passed - important to report and error and that is what 1st variant does.

提交回复
热议问题