Advertisement
bacco

Different Integers Size

May 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DifferentIntegersSize
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string number = Console.ReadLine();
  10.             string result = string.Empty;
  11.  
  12.             try
  13.             {
  14.                 sbyte.Parse(number);
  15.                 result += "* sbyte\n";
  16.             }
  17.             catch{}
  18.  
  19.             try
  20.             {
  21.                 byte.Parse(number);
  22.                 result += "* byte\n";
  23.             }
  24.             catch { }
  25.  
  26.             try
  27.             {
  28.                 short.Parse(number);
  29.                 result += "* short\n";
  30.             }
  31.             catch { }
  32.  
  33.             try
  34.             {
  35.                 ushort.Parse(number);
  36.                 result += "* ushort\n";
  37.             }
  38.             catch { }
  39.  
  40.             try
  41.             {
  42.                 int.Parse(number);
  43.                 result += "* int\n";
  44.             }
  45.             catch { }
  46.  
  47.             try
  48.             {
  49.                 uint.Parse(number);
  50.                 result += "* uint\n";
  51.             }
  52.             catch { }
  53.  
  54.             try
  55.             {
  56.                 long.Parse(number);
  57.                 result += "* long\n";
  58.             }
  59.             catch
  60.             {
  61.                 Console.WriteLine("{0} can't fit in any type", number);
  62.                 return;
  63.             }
  64.  
  65.             Console.WriteLine($"{number} can fit in:\n" + result);
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement