Null check value types passed via parameters

TheAkhemist

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();
...
}
sstan

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to check for a null value in a variable passed as a reference

From Dev

Are value types boxed when passed as generic parameters with an interface constraint?

From Dev

Compare function failing when null value passed to one of the parameters

From Dev

WebAPI passed post parameters is null

From Dev

Redirect via HTTPFound parameters not being passed

From Dev

extending Lua: check number of parameters passed to a function

From Dev

How to check for wrong number of parameters passed to a function

From Dev

Check the number of parameters passed in Python function

From Dev

check if no parameters passed in groovy closure before calling it

From Dev

Value is null when passed as parameter

From Dev

Null value for anonymous types

From Dev

Value of parameters is null

From Dev

PHP: Check is null was passed as a parameter or assigned as the default

From Dev

Check for null parameters using an attribute

From Dev

Check for null parameters using an attribute

From Dev

Check null database value

From Dev

Check if value exists or is null

From Dev

Check if DatePicker value is null

From Dev

Check if Eval("VALUE") is null

From Dev

unititialized copy via CRTP pattern passed by value

From Dev

JustMock - check value of passed method argument

From Dev

MYSQL check if a table value is contained in a passed string

From Dev

JustMock - check value of passed method argument

From Dev

Finding size of types passed via command line argument

From Dev

how to throw InvalidArgumentException if null value passed to list

From Dev

Heroku app crashing when null value passed

From Dev

How are parameters passed to Linux system call ? Via register or stack?

From Dev

Check parameters passed to constructor when using initialization lists - C++

From Dev

Passing extra parameters via check_box?

Related Related

  1. 1

    How to check for a null value in a variable passed as a reference

  2. 2

    Are value types boxed when passed as generic parameters with an interface constraint?

  3. 3

    Compare function failing when null value passed to one of the parameters

  4. 4

    WebAPI passed post parameters is null

  5. 5

    Redirect via HTTPFound parameters not being passed

  6. 6

    extending Lua: check number of parameters passed to a function

  7. 7

    How to check for wrong number of parameters passed to a function

  8. 8

    Check the number of parameters passed in Python function

  9. 9

    check if no parameters passed in groovy closure before calling it

  10. 10

    Value is null when passed as parameter

  11. 11

    Null value for anonymous types

  12. 12

    Value of parameters is null

  13. 13

    PHP: Check is null was passed as a parameter or assigned as the default

  14. 14

    Check for null parameters using an attribute

  15. 15

    Check for null parameters using an attribute

  16. 16

    Check null database value

  17. 17

    Check if value exists or is null

  18. 18

    Check if DatePicker value is null

  19. 19

    Check if Eval("VALUE") is null

  20. 20

    unititialized copy via CRTP pattern passed by value

  21. 21

    JustMock - check value of passed method argument

  22. 22

    MYSQL check if a table value is contained in a passed string

  23. 23

    JustMock - check value of passed method argument

  24. 24

    Finding size of types passed via command line argument

  25. 25

    how to throw InvalidArgumentException if null value passed to list

  26. 26

    Heroku app crashing when null value passed

  27. 27

    How are parameters passed to Linux system call ? Via register or stack?

  28. 28

    Check parameters passed to constructor when using initialization lists - C++

  29. 29

    Passing extra parameters via check_box?

HotTag

Archive