 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# NullReferenceException
NullReferenceException occurs when you try to to access member fields, or function types that points to null.
Here is an example −
Example
using System;
class Demo {
   static void Main() {
      string str = null;
      if (str.Length > 0) {
         Console.WriteLine(str);
      }
   }
}
Output
The following is the output. It throws NullReferenceException, since you are tryonhg access a memebt that points to null −
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at Demo.Main () [0x00002] in <0bc5fbf292484d5194a19866ae5c2018>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object at Demo.Main () [0x00002] in <0bc5fbf292484d5194a19866ae5c2018>:0
Advertisements
                    