Advertisement
ElviraPetkova

DataTypes

Jan 30th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace FundamentalsIntro
  5. {
  6.     public class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             bool boolean;
  11.             int integer;
  12.             double floatPoint;
  13.             char character;
  14.            
  15.             while(true)
  16.             {
  17.                 string line = Console.ReadLine();
  18.                
  19.                 if(line == "END")
  20.                 {
  21.                     break;
  22.                 }
  23.                
  24.                 bool isInteger = int.TryParse(line, out integer);
  25.                 bool isDouble = double.TryParse(line, out floatPoint);
  26.                 bool isChar = char.TryParse(line, out character);
  27.                 bool isBoolean = bool.TryParse(line, out boolean);
  28.                
  29.                 if(isInteger)
  30.                 {
  31.                     Console.WriteLine("{0} is integer type", integer);
  32.                 }
  33.                 else if(isDouble)
  34.                 {
  35.                     Console.WriteLine("{0} is floating point type", line);
  36.                 }
  37.                 else if(isChar)
  38.                 {
  39.                     Console.WriteLine("{0} is character type", character);
  40.                 }
  41.                 else if(isBoolean)
  42.                 {
  43.                     Console.WriteLine("{0} is boolean type", line);
  44.                 }
  45.                 else
  46.                 {
  47.                     Console.WriteLine("{0} is string type", line);
  48.                 }
  49.                
  50.             }
  51.  
  52.         }
  53.        
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement