Advertisement
po-razli4en

Different Integers Size

May 26th, 2016
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class Pro_17_DiffIntegerSize
  9. {
  10.     static void Main()
  11.     {
  12.         string input = Console.ReadLine();
  13.         try
  14.         {
  15.             sbyte number = sbyte.Parse(input);
  16.             Console.WriteLine("{0} can fit in:", number);
  17.             Console.WriteLine("* sbyte");
  18.             Console.WriteLine("* short");
  19.             Console.WriteLine("* int");
  20.             Console.WriteLine("* long");
  21.         }
  22.         catch (OverflowException)
  23.         {
  24.             try
  25.             {
  26.                 byte number = byte.Parse(input);
  27.                 Console.WriteLine("{0} can fit in:", number);
  28.                 Console.WriteLine("* byte");
  29.                 Console.WriteLine("* short");
  30.                 Console.WriteLine("* ushort");
  31.                 Console.WriteLine("* int");
  32.                 Console.WriteLine("* uint");
  33.                 Console.WriteLine("* long");
  34.  
  35.             }
  36.             catch (OverflowException)
  37.             {
  38.                 try
  39.                 {
  40.                     short number = short.Parse(input);
  41.                     Console.WriteLine("{0} can fit in:", number);
  42.                     Console.WriteLine("* short");
  43.  
  44.                     Console.WriteLine("* int");
  45.  
  46.                     Console.WriteLine("* long");
  47.  
  48.                 }
  49.                 catch (OverflowException)
  50.                 {
  51.                     try
  52.                     {
  53.                         ushort number = ushort.Parse(input);
  54.                         Console.WriteLine("{0} can fit in:", number);
  55.                         Console.WriteLine("* ushort");
  56.                         Console.WriteLine("* int");
  57.                         Console.WriteLine("* uint");
  58.                         Console.WriteLine("* long");
  59.  
  60.                     }
  61.                     catch (OverflowException)
  62.                     {
  63.                         try
  64.                         {
  65.                             int number = int.Parse(input);
  66.                             Console.WriteLine("{0} can fit in:", number);
  67.                             Console.WriteLine("* int");
  68.                             Console.WriteLine("* uint");
  69.                             Console.WriteLine("* long");
  70.  
  71.                         }
  72.                         catch (OverflowException)
  73.                         {
  74.                             try
  75.                             {
  76.                                 uint number = uint.Parse(input);
  77.                                 Console.WriteLine("{0} can fit in:", number);
  78.                                 Console.WriteLine("* uint");
  79.                                 Console.WriteLine("* long");
  80.  
  81.                             }
  82.                             catch (OverflowException)
  83.                             {
  84.                                 try
  85.                                 {
  86.                                     long number = long.Parse(input);
  87.                                     Console.WriteLine("{0} can fit in:", number);
  88.                                     Console.WriteLine("* long");
  89.  
  90.                                 }
  91.                                 catch (OverflowException)
  92.                                 {
  93.  
  94.                                     Console.WriteLine("{0} can't fit in any type", input);
  95.  
  96.                                 }
  97.                             }
  98.                         }
  99.                     }
  100.                 }
  101.             }
  102.         }
  103.  
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement