Considering that value types are always initalised by default and never null would it be worth to null check value types passed in to methods via parameters?
E.g. is it worth performing the following check
public void Method(Guid x)
{
if (x == null)
throw new ArgumentNullException();
...
}
Though the condition is technically valid (because of operator overload rules and nullable types), it can only ever evaluate to false
. That's why, in some cases, you will get a compiler warning to let you know that the only possible outcome is false
.
So, unless there is more to your question, it comes down to asking if this code is worth it:
public void Method(Guid x)
{
if (false)
throw new ArgumentNullException();
...
}
The answer should be pretty obvious.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments