Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
ArgumentNullException in C#
The exception thrown when a null reference is passed to a method that does not accept it as a valid argument.
Let us see an example.
When we set a null parameter to int.Parse() method, then ArgumentNullException is thrown as shown below −
Example
using System;
class Demo {
static void Main() {
string val = null;
int res = int.Parse(val); // error is thrown
}
}
Output
The following error is thrown when the above program is compiled since we have passed a null value.
Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Advertisements
