• +91 9723535972
  • info@interviewmaterial.com

CSharp Interview Questions and Answers

Question - How you can implement nullable<> types in C#? explain with the syntax of Nullable type.

Answer -

In C#, you cannot put a null value directly into any variable and the compiler does not support it. So, the revised version C# 2.0 provides you with a special feature that will assign a null value to a variable that is called as the Nullable type. You cannot make the nullable types to work with value types. Nullable value can only work with the reference types as it already has a null value. System.Nullable structure creates the instance nullable type, where T defines the data type. This T contains a non-nullable value type that can be any data type you want.
Syntax

Nullable variable_name=null;
OR
Datatype? variable_name=null;

There is no possibility that you can access the value of the nullable value type directly with assigning the value. For getting its original assigned value you have to use the method GetValueOrDefault(). If the value is null then it will provide zero as it is its default value.

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners