Declare a variable and assign a value


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet declares variables of all the C# types without initializing them and assigns values to them.

class VariableDeclarations
{
   public static void Main()
   {
   // Type      Identifier   Assignment (maximum value)
      bool	aBool;	     aBool    = true;
      byte	aByte;	     aByte    = 255;
      decimal	aDecimal;    aDecimal = 0.99m;
      double	aDouble;     aDouble  = 1.7 * 10308;
      char	aChar;	     aChar    = '\uFFFF';
      float	aFloat;	     aFloat   = 3.4f * 1038f;
      int	aInt;	     aInt     = 2147483647;
      long	aLong;	     aLong    = 9223372036854775807;
      object	aObject;     aObject  = new Object();
      sbyte	aSbyte;	     aSbyte   = 127;
      uint	aUint;	     aUint    = 4294967295;
      short	aShort;	     aShort   = 32767;
      string	aString;     aString  = "Sample";
      ushort	aUshort;     aUshort  = 65535;
      ulong	aUlong;	     aUlong   = 18446744073709551615;
   }
}


Personal tools