Advertisement
Qrist

Greater of Two Values (int,char,string)

Apr 16th, 2020
183
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.  
  3. class Program
  4. {
  5.     public static void Main(string[] args)
  6.     {
  7.         string type = Console.ReadLine();
  8.         string first = Console.ReadLine();
  9.         string second = Console.ReadLine();
  10.         string result = GetMAx(type, first, second);
  11.         Console.WriteLine(result);        
  12.     }    
  13.     public static string GetMAx(string type,string first,string second)
  14.     {
  15.         int result1 = 0;
  16.         int result2 = 0;
  17.         if (type == "int")
  18.         {
  19.             result1 = int.Parse(first);
  20.             result2 = int.Parse(second);
  21.         }
  22.         else if (type == "char")
  23.         {
  24.             result1 = char.Parse(first);
  25.             result2 = char.Parse(second);
  26.         }
  27.         else if (type == "string")
  28.         {
  29.            result1 = first.CompareTo(second);
  30.            result2 = first.CompareTo(second);
  31.         }
  32.         if(result1>result2)
  33.         {
  34.             return first;
  35.         }
  36.         else
  37.         {
  38.             return second;
  39.         }      
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement