What is a Null literal in C#?

 Posted by Goud.Kv on 9/3/2014 | Category: C# Interview questions | Views: 287 | Points: 40
Answer:

Null literal is a null type which indicates that the reference is pointing to no object.

Example,
public class Employee

{
int name, id;
}
static void Main()
{
Employee emp = null;
..............;
}
In the above example, we have an Employee class.
emp is an object created to Employee.
But it is not referring to any object.

If we try to call the variables like,
emp.name;

emp.id;
will throws an error at the runtime which is known as Null Reference Exception.


Asked In: Spotted While Learning | Alert Moderator 

Comments or Responses

Login to post response