skipter icon

C# Compare int/string/char / Methods

skipter | PRO | 06/13/17 08:00:44 PM UTC | 0 ⭐ | 328 👁️ | Never ⏰ | []
C# |

1.83 KB

|

None

|

0 👍

/

0 👎

using System;
namespace DataTypes___Lab
{
    class Program
    {
        static void Main(string[] args)
        {
            var enterVariablae = Console.ReadLine();
            if (enterVariablae == "int")
            {
                int first = int.Parse(Console.ReadLine());
                int second = int.Parse(Console.ReadLine());
                GetMax(first, second);
            } else if (enterVariablae == "string")
            {
                string first = Console.ReadLine();
                string second = Console.ReadLine();
                GetMax(first, second);
            } else if (enterVariablae == "char")
            {
                char first = char.Parse(Console.ReadLine());
                char second = char.Parse(Console.ReadLine());
                GetMax(first, second);
            }
        }
        static void GetMax(int first, int second)
        {          
            if (first > second)
            {
                Console.WriteLine(first);               
            } else 
            {
                Console.WriteLine(second);               
            }             
        }
        static void GetMax(string first, string second)            
        {
            var compare = first.CompareTo(second);
            if (compare > 0)
            {
                Console.WriteLine(first);               
            } else 
            {
                Console.WriteLine(second);               
            }             
        }
        static void GetMax(char first, char second)
        {            
            if ((char) first > (char) second)
            {
                Console.WriteLine(first);              
            } else
            {
                Console.WriteLine(second);         
            }             
        }
    }
}

Comments