Where to check if an object is null or not?

前端 未结 13 1466
广开言路
广开言路 2020-12-17 10:18

Where do you check if an object that you are passing to a method is null or not?

Should an object need to be tested before calling a method? or within the method tha

13条回答
  •  旧巷少年郎
    2020-12-17 10:56

    There is only one occasion that a constructor can return null [new() on a Nullable] - so the calling code doesn't need to check.

    The callee probably should check; throwing an ArgumentNullException if it was null. In .NET 4.0 this will be better served by code contracts. But not yet ;-p

提交回复
热议问题