codescracker


c#

C# Nullable



« Previous Tutorial Next Tutorial »


Nullable is a special data type in C#. You can assign both, that is, normal range of values as well as null values to nullable variables. Here is the general form to declare nullable type variable in C#:

data-type? variable-name = null;

C# Nullable Example

Here is an example program, demonstrating the nullable type variable in C#:

/* C# Nullable - Example Program */
		
using System;
namespace NullableExample
{
   class NullableClass
   {
      static void Main(string[] args)
      {
         int? m = null;
         int? n = 45;
         double? o = new double?();
         double? p = 3.14157;
         bool? boolval = new bool?();
         Console.WriteLine("Nullables at Show = {0}, {1}, {2}, {3}", m, n, o, p);
         Console.WriteLine("A Nullable boolean value = {0}", boolval);
         Console.ReadLine();
      }
   }
}

When we compile and run the above program, it will produce the following output:

Nullables at Show = , 45,  , 3.14157
A Nullable boolean value =

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test