
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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