mercredi 3 janvier 2018

If statement is not working! Why?

So, I was doing some C# exercises and I got a problem, whenever I run the program it doesn't go through the If statement, it stops right before it. I'm going to put the script here so you guys can have an idea about what I'm talking. The program reads something from the keyboard and prints the input.

namespace CeV_003
{
    class Ex003
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Will you type a number or a letter? [N/L]? Type above:");
            string check = Console.ReadLine().Trim().ToUpper();
            Console.WriteLine(check);
            if (check == "L")
            {
                string letter = Console.ReadLine().Trim();
                Console.WriteLine(letter.GetType());
            }
            else if (check == "N")
            {
                int num = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine(num.GetType());
            }
            else
            {
                Console.WriteLine("Unknown Command!");
            }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire