Faster way to perform checks on method arguments

Posted by AndyC on Stack Overflow See other posts from Stack Overflow or by AndyC
Published on 2010-04-13T17:02:58Z Indexed on 2010/04/13 17:13 UTC
Read the original article Hit count: 334

Filed under:
|
|

This is mostly just out of curiosity, and is potentially a silly question. :)

I have a method like this:

public void MyMethod(string arg1, string arg2, int arg3, string arg4, MyClass arg5)
{
    // some magic here
}

None of the arguments can be null, and none of the string arguments can equal String.Empty.

Instead of me having a big list of:

if(arg1 == string.Empty || arg1 == null)
{
    throw new ArgumentException("issue with arg1");
}

is there a quicker way to just check all the string arguments?

Apologies if my question isn't clear.

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about exceptions