TheBulgarianWolf

Data Type Finder

Oct 9th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. namespace SoftuniExercisesWithVariables
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             while (true)
  11.             {
  12.                 string input = Console.ReadLine();
  13.                 if (input == "END")
  14.                 {
  15.                     break;
  16.                 }
  17.  
  18.                 bool integerChek = int.TryParse(input, out int integer);
  19.                 bool doubleChek = double.TryParse(input, out double floating);
  20.                 bool charChek = char.TryParse(input, out char mychar);
  21.                 bool boolChek = bool.TryParse(input, out bool boolean);
  22.  
  23.                 if (integerChek)
  24.                 {
  25.                     Console.WriteLine($"{input} is integer type");
  26.                 }
  27.                 else if (doubleChek)
  28.                 {
  29.                     Console.WriteLine($"{input} is floating point type");
  30.                 }
  31.                 else if (charChek)
  32.                 {
  33.                     Console.WriteLine($"{input} is character type");
  34.                 }
  35.                 else if (boolChek)
  36.                 {
  37.                     Console.WriteLine($"{input} is boolean type");
  38.                 }
  39.                 else
  40.                 {
  41.                     Console.WriteLine($"{input} is string type");
  42.                 }
  43.  
  44.             }
  45.  
  46.         }
  47.     }
  48. }
  49.  
Add Comment
Please, Sign In to add comment