nullable types can assign normal range of values as well as null values. - CSharp Language Basics

CSharp examples for Language Basics:Nullable

Introduction

For example, you can store any value from -2,147,483,648 to 2,147,483,647 or null in a Nullable<Int32> variable.

You can assign true, false, or null in a Nullable<bool> variable.

Syntax for declaring a nullable type is as follows:

<data_type> ? <variable_name> = null;

The following example demonstrates use of nullable data types.

Demo Code

using System;/*from   w w  w.  j  a  v a2s .  c o  m*/
class MainClass{
   static void Main(string[] args) {
      int? num1 = null;
      int? num2 = 45;
      double? num3 = new double?();
      double? num4 = 3.14157;
      bool? boolval = new bool?();
      Console.WriteLine("Nullables at Show: {0}, {1}, {2}, {3}", num1, num2, num3, num4);
      Console.WriteLine("A Nullable boolean value: {0}", boolval);
   }
}

Result


Related Tutorials