Advertisement
WindFell

Greater Of Two Values

Aug 2nd, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2.  
  3. class GreaterOfTwoValues
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         string type = Console.ReadLine();
  8.  
  9.         string max = "";
  10.  
  11.         switch (type)
  12.         {
  13.             case "int":
  14.                 int firstInt = int.Parse(Console.ReadLine());
  15.                 int secondInt = int.Parse(Console.ReadLine());
  16.                 max = GetMax(firstInt, secondInt).ToString();
  17.                 break;
  18.             case "char":
  19.                 char firstChar = char.Parse(Console.ReadLine());
  20.                 char secondChar = char.Parse(Console.ReadLine());
  21.                 max = GetMax(firstChar, secondChar).ToString();
  22.                 break;
  23.             case "string":
  24.                 string firstString = Console.ReadLine();
  25.                 string secondString = Console.ReadLine();
  26.                 max = GetMax(firstString, secondString);
  27.                 break;
  28.         }
  29.  
  30.         Console.WriteLine(max);
  31.     }
  32.  
  33.     static int GetMax(int first, int second)
  34.     {
  35.         if (first >= second)
  36.         {
  37.             return first;
  38.         }
  39.  
  40.         return second;
  41.     }
  42.  
  43.     static char GetMax(char first, char second)
  44.     {
  45.         if (first >= second)
  46.         {
  47.             return first;
  48.         }
  49.  
  50.         return second;
  51.     }
  52.  
  53.     static string GetMax(string first, string second)
  54.     {
  55.         if (first.CompareTo(second) >= 0)
  56.         {
  57.             return first;
  58.         }
  59.  
  60.         return second;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement