Q: When to check for null arguments and throw ArgumentNullException I have some code like this:
public void someMethod (Object x)
{
   if (x == null) throw new ArgumentNullException ();

   // more code...
}

Should I now do this:
public void myMethod (Object z)
{
    someMethod (z);
}

Or this:
public void myMethod (Object z)
{
    if (z == null) throw new ArgumentNullException ();

    someMethod (z);
}

Note: I prefer speed of execution in this class

A: In my opinion, all public methods should validate their inputs, even if it is somewhat redundant. Having said that, I often compile the more expensive validation and code contracts using conditional compilation directives so that release builds only perform the most critical diagnostics and validation. 
Checking for a null argument is an important and inexpensive operation which will have only the smallest performance impact over millions of calls.
Overloaded methods that all call a common internal method might perform less checking with the knowledge that their actual implementation performs full validation.
For what it's worth, most of the BCL source code I've seen from Microsoft errs on the side of more validation, diagnostics, and contract adherence rather than less.

A: In my opinion someMethod should be responsible for throwing exception if any parameter passed to it is null. Ideally you should not call somemethod from mymethod if z is null. You should add check for null in myMethod but let somemethod throw the exception
public void myMethod (Object z)
{
    someMethod (z);
}

I would suggest the above one. By the way these micro level optimization won't give you any significant performance boost

A: I would go by this:


*

*If your method has certain requirements for the arguments passed in (like "must not be null") then it should check for that and throw if thats appropriate

*If your method calls other method it should not have to check their argument requirements as well - it's the other methods job to do that anyway. You are just duplicating code - remember DRY (Don't Repeat Yourself)


So in your case I would not check for null in myMethod again unless myMethod also relies itself on z not being null. I doubt that there are any practically relevant speed differences (remember: "premature optimization is the root of all evil")
