- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Null Pointer Exception in C#
NullReferenceException is a C# version of NullPointerException. To handle and catch it in C#, use try-catch.
The below example shows that a variable is set to null and when we try to print it, it throws an exception that gets caught in the catch −
Try { a = null; Console.WriteLine(a); }catch (NullPointerException ex) { Console.WriteLine("Variable is Null!"); }
The above will allow the exception to be caught and use catch for it.
- Related Articles
- Null Pointer Exception in Java Programming
- NULL pointer in C
- What is null pointer exception in Java and how to fix it?
- Differentiate the NULL pointer with Void pointer in C language
- Calling class method through NULL class pointer in C++
- How to capture null reference exception in C#?
- Why is address zero used for the null pointer in C/C++?
- Calling a member function on a NULL object pointer in C++
- Why do we check for a NULL pointer before deleting in C/C++?
- Double Pointer (Pointer to Pointer) in C
- What should we assign to a C++ pointer: A Null or 0?
- Explain the concept of pointer to pointer and void pointer in C language?
- How to define pointer to pointer in C language?
- Pointer Arithmetic in C/C++
- Function Pointer in C

Advertisements