Home » Tutorials » C# » Nullable types in C#

Nullable types in C#

Method Overloading in C#
MVC Architectural Pattern

Nullable types in C#

C# types are divided into below two categories:

  1. Value Types: int, float, double, struct etc.
  2. Reference Type: string, class, Interface, delegates, arrays etc.
  • By default value types are non nullable. To have nullable value type we have to use ?
  • Nullable type is work like bridge between C# types and Database Types.
  • int a=0 (a is non nullable variable, can’t assign null to this variable)
  • int? a= null (a is nullable int variable, so we can assign null value)
  • string str=null (string is a reference type, so we could assign null directly to string type variable)

Let’s understand using below example:


He is not employee of this company.

Another example with int datatype: 


Final Jobs available: 10


In above example, you can notice that we have used “NoOfAvailableJobs.Value“, which will return int so we could directly assign to our FinalJobAvailable variable. Please refer below image for your reference



Here we could also use single line of code instead of writing these much lines as below



Hello friends, My self Dhruv Sheth, I have more than 6 years of Industrial experience as a Software Developer. In my career I got chance to work with asp.net, c#,Web API, JavaScript, JQuery, WPF, WCF , Windows Application, PostScript, vb.net, GhostScript etc. So I have decided to share my knowledge with everyone and finally I have come up with TechnoThirsty.

Leave a Reply

Your email address will not be published. Required fields are marked *


Time limit is exhausted. Please reload CAPTCHA.

The content is copyrighted to technothirsty.com and may not be reproduced on other websites without permission from the owner.You may contact us using the information below.