Advertisement
AnitaN

02.PrimitiveDataTypesVariables/01.DeclareVariables

Mar 9th, 2014
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. //Problem 1.    Declare Variables
  2. //Declare five variables choosing for each of them the most appropriate of the types byte, sbyte, short, ushort, int, uint, long, ulong to represent the following values: 52130, -115, 4825932, 97, -10000. Choose a large enough type for each number to ensure it will fit in it. Try to compile the code.
  3.  
  4. using System;
  5.  
  6. class DeclareVariables
  7. {
  8.     static void Main()
  9.     {
  10.         //Declare variables
  11.         //ushort (0 to 65,535): unsigned 16-bit
  12.         ushort valueA = 52130;
  13.         //sbyte (-128 to 127): signed 8-bit
  14.         sbyte valueB = -115;
  15.         //uint (0 to 4,294,967,295): unsigned 32-bit
  16.         uint valueC = 4825932;
  17.         //byte (0 to 255): unsigned 8-bit
  18.         byte valueD = 97;
  19.         //short (-32,768 to 32,767): signed 16-bit
  20.         short valueE = -10000;
  21.         //Print to Console
  22.         Console.WriteLine("Type ushort {0}", valueA);
  23.         Console.WriteLine("Type sbyte {0}", valueB);
  24.         Console.WriteLine("Type uint {0}", valueC);
  25.         Console.WriteLine("Type byte {0}", valueD);
  26.         Console.WriteLine("Type short {0}", valueE);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement