Difference between ARGUMENTNULL EXCEPTION & null reference exception?

can you please explain?
thanks

@Akbar_Badhusa
null reference exception occurs when you use a variable and it’s value is null.

argument null exception is when you pass an invalid argument to a method. Your method expects a non null argument.

Regards

Hi,

Hope the following will help you.

Null Reference exception

Object (variable) which is called method or got/set property is null.

strA=Nothing
strB="test"

Then

strA.Contains(strB)

throws Null Reference Exception because object:strA is null.

ArgumentNullExecption

One or more argument of method is null.

strA="test"
strB=Nothing

Then

strA.Contains(strB)

throws Argument Null Exception because argument of Contain is null.

Regards,

1 Like