Declare and initialize a variable

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
C# Code Snippets

C# Source Code Bank

See also …
edit

This C# code snippet declares and initializes variables of all the C# types.

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

Today's Deals: Electronics

Personal tools