Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Wednesday, June 20

C# Nullable Types

When you declare a variable, you ask the compiler to reserve a certain area and amount of memory to eventually hold a value for that variable. At that time, no clear value is stored in that reserved area of memory. Instead, the area gets filled with garbage, which value is referred to as null when it cannot be clearly determined. A null value is not 0 because 0 is an actual value.

 In C#, normally, not all variables can hold null values. But if you want to do so you can do it.

There is a tow way of declaring Nullable variables, in here I will mention both ways.   
  

System.Nullable<T> variableName
-Or-
T? variableName 

T is the underlying type of the Nullable type. T can be any value type including struct. It cannot be a reference type.

E.g.:  int? i = null;
  
When you create a Nullable of Int32, it can be assigned any value from -2147483648 to 2147483647 or it can be assigned the null value. 

The Nullable type modifier enables C# to create value-type variables that indicate an undefined value. 
 

Tuesday, June 19

I promise you that you will learn something new every day

Welcome to my blog… It will be great fun to have new reader. I promise you that you will learn something new every day.

The purpose of this blog is to share my knowledge with readers. In this blog you can find posts related many topics, but most will be about Information Technology, programming languages, tips and tricks.