Throwing ArgumentNullException in constructor?

前端 未结 4 1689
眼角桃花
眼角桃花 2020-12-08 02:34

For a constructor with a single parameter, is it OK to throw an ArgumentNullException inside the constructor if the parameter is null/empty? OR, should it be thrown in the m

4条回答
  •  有刺的猬
    2020-12-08 03:04

    From what it sounds like, you pass in a parameter into the constructor to be held by the class for use in some other method later on. If you're not actually using the argument in the constructor, you should probably think about moving the argument to be a parameter of the method that's actually using it.

提交回复
热议问题