Advertisement
skipter

C# Compare int/string/char / Methods

Jun 13th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. namespace DataTypes___Lab
  3. {
  4.     class Program
  5.     {
  6.         static void Main(string[] args)
  7.         {
  8.             var enterVariablae = Console.ReadLine();
  9.             if (enterVariablae == "int")
  10.             {
  11.                 int first = int.Parse(Console.ReadLine());
  12.                 int second = int.Parse(Console.ReadLine());
  13.                 GetMax(first, second);
  14.             } else if (enterVariablae == "string")
  15.             {
  16.                 string first = Console.ReadLine();
  17.                 string second = Console.ReadLine();
  18.                 GetMax(first, second);
  19.             } else if (enterVariablae == "char")
  20.             {
  21.                 char first = char.Parse(Console.ReadLine());
  22.                 char second = char.Parse(Console.ReadLine());
  23.                 GetMax(first, second);
  24.             }
  25.         }
  26.         static void GetMax(int first, int second)
  27.         {          
  28.             if (first > second)
  29.             {
  30.                 Console.WriteLine(first);              
  31.             } else
  32.             {
  33.                 Console.WriteLine(second);              
  34.             }            
  35.         }
  36.         static void GetMax(string first, string second)            
  37.         {
  38.             var compare = first.CompareTo(second);
  39.             if (compare > 0)
  40.             {
  41.                 Console.WriteLine(first);              
  42.             } else
  43.             {
  44.                 Console.WriteLine(second);              
  45.             }            
  46.         }
  47.         static void GetMax(char first, char second)
  48.         {            
  49.             if ((char) first > (char) second)
  50.             {
  51.                 Console.WriteLine(first);              
  52.             } else
  53.             {
  54.                 Console.WriteLine(second);        
  55.             }            
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement