Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 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. using System.Numerics;
  7.  
  8. namespace ConsoleApp10
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string n = Console.ReadLine();
  15.             int counter = 0;
  16.             List<string> list = new List<string>();
  17.             NewMethod(n, ref counter, list);
  18.             if (counter == 0)
  19.             {
  20.                 Console.WriteLine($"{n} can't fit in any type");
  21.             }
  22.             else
  23.             {
  24.                 Console.WriteLine($"{n} can fit in:");
  25.             for (int i = list.Count - 1; i >= 0; i--)
  26.             {
  27.                 Console.WriteLine(list[i]);
  28.             }
  29.             }
  30.  
  31.         }
  32.  
  33.         private static void NewMethod(string n, ref int counter, List<string> list)
  34.         {
  35.             try
  36.             {
  37.                 long.Parse(n);
  38.             }
  39.             catch (Exception)
  40.             {
  41.                
  42.                 return;
  43.             }
  44.             list.Add("* long");
  45.             counter++;
  46.             if (!n.Contains("-"))
  47.             {
  48.                 try
  49.                 {
  50.                     uint.Parse(n);
  51.                 }
  52.                 catch (Exception)
  53.                 {
  54.  
  55.                     return;
  56.                 }
  57.                 list.Add("* uint");
  58.                 counter++;
  59.             }
  60.             try
  61.             {
  62.                 int.Parse(n);
  63.             }
  64.             catch (Exception)
  65.             {
  66.  
  67.                 return;
  68.             }
  69.             list.Add("* int");
  70.             counter++;
  71.             if (!n.Contains("-"))
  72.             {
  73.                 try
  74.                 {
  75.                     ushort.Parse(n);
  76.                 }
  77.                 catch (Exception)
  78.                 {
  79.  
  80.                     return;
  81.                 }
  82.                 list.Add("* ushort");
  83.                 counter++;
  84.             }
  85.             try
  86.             {
  87.                 short.Parse(n);
  88.             }
  89.             catch (Exception)
  90.             {
  91.  
  92.                 return;
  93.             }
  94.             list.Add("* short");
  95.             counter++;
  96.             try
  97.             {
  98.                 byte.Parse(n);
  99.             }
  100.             catch (Exception)
  101.             {
  102.  
  103.                 return;
  104.             }
  105.             list.Add("* byte");
  106.             counter++;
  107.             try
  108.             {
  109.                 sbyte.Parse(n);
  110.             }
  111.             catch (Exception)
  112.             {
  113.  
  114.                 return;
  115.             }
  116.             list.Add("* sbyte");
  117.             counter++;
  118.         }
  119.  
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement