VelizarAvramov

18. Different Integers Size

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