Value default value

In this chapter you will learn:

  1. Data type default value

Data type default value

The following code shows the data type default value. It prints out the value without assign anything to them.

using System;/*from   j a  va2s  . c  om*/

class MainClass
{
  public sbyte  theSignedByte;
  public byte    theByte;
  public short  theShort;
  public ushort  theUShort;
  public int    theInt;
  public uint    theUInt;
  public long    theLong;
  public ulong  theULong;
  public char    theChar;
  public float  theFloat;
  public double  theDouble;
  public bool    theBool;
  public decimal  theDecimal;
  public string  theStr;
  public object  theObj;

  public static int Main(string[] args)
  {
    MainClass v = new MainClass();

    Console.WriteLine("bool: {0}", v.theBool);
    Console.WriteLine("byte: {0}", v.theByte);
    Console.WriteLine("char: {0}", v.theChar);
    Console.WriteLine("decimal: {0}", v.theDecimal);
    Console.WriteLine("double: {0}", v.theDouble);
    Console.WriteLine("float: {0}", v.theFloat);
    Console.WriteLine("int: {0}", v.theInt);
    Console.WriteLine("long: {0}", v.theLong);
    Console.WriteLine("object: {0}", v.theObj);
    Console.WriteLine("short: {0}", v.theShort);
    Console.WriteLine("signed byte: {0}", v.theSignedByte);
    Console.WriteLine("string: {0}", v.theStr);
    Console.WriteLine("unsigned int: {0}", v.theUInt);
    Console.WriteLine("unsigned long: {0}", v.theULong);
    Console.WriteLine("unsigned short: {0}", v.theUShort);
    return 0;
  }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Anonymous types
  2. Limitations on anonymous types
  3. Initializing Anonymous Type Arrays
Home » C# Tutorial » Data Types
C# Data Types
Value type vs reference type
Literals
Value default value
Anonymous type