Advertisement
Guest User

DifferentIntegerSize

a guest
Sep 26th, 2016
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2.    
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         // sbyte < byte < short < ushort < int < uint < long
  8.         bool canFit = false;
  9.         string numStr = Console.ReadLine();
  10.         string message = "";
  11.  
  12.         try
  13.         {
  14.             sbyte sbyteNum = sbyte.Parse(numStr);
  15.             message += "* sbyte\n";
  16.             canFit = true;
  17.         }
  18.         catch (Exception)
  19.         {            
  20.         }
  21.  
  22.         try
  23.         {
  24.             byte byteNum = byte.Parse(numStr);
  25.             message += "* byte\n";
  26.             canFit = true;
  27.         }
  28.         catch (Exception)
  29.         {          
  30.         }
  31.  
  32.         try
  33.         {
  34.             short shortNum = short.Parse(numStr);
  35.             message += "* short\n";
  36.             canFit = true;
  37.         }
  38.         catch (Exception)
  39.         {            
  40.         }
  41.  
  42.         try
  43.         {
  44.             ushort ushortNum = ushort.Parse(numStr);
  45.             message += "* ushort\n";
  46.             canFit = true;
  47.         }
  48.         catch (Exception)
  49.         {          
  50.         }
  51.  
  52.         try
  53.         {
  54.             int intNum = int.Parse(numStr);
  55.             message += "* int\n";
  56.             canFit = true;
  57.         }
  58.         catch (Exception)
  59.         {          
  60.         }
  61.  
  62.         try
  63.         {
  64.             uint uintNum = uint.Parse(numStr);
  65.             message += "* uint\n";
  66.             canFit = true;
  67.         }
  68.         catch (Exception)
  69.         {          
  70.         }
  71.  
  72.         try
  73.         {
  74.             long longNum = long.Parse(numStr);
  75.             message += "* long\n";
  76.             canFit = true;
  77.         }
  78.         catch (Exception)
  79.         {          
  80.         }
  81.  
  82.         if (canFit)
  83.         {
  84.             Console.WriteLine("{0} can fit in:", numStr);
  85.             Console.WriteLine(message);
  86.         }
  87.         else
  88.         {
  89.             Console.WriteLine("{0} can't fit in any type", numStr);
  90.         }
  91.  
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement