How to deal with 'argumentnullexception in c#?'

Example:

string str = null;
Console.WriteLine(str.ToString());

Trying to call a method on a null argument.

Solution:

This exception arises when a null argument is passed to a method that doesn't accept it as valid. Always check for `null` before passing to methods that can't handle it.


if(str != null) {
    Console.WriteLine(str.ToString());
}

Beginner's Guide to C#