Read string from console and check its value - CSharp Language Basics

CSharp examples for Language Basics:Console

Description

Read string from console and check its value

Demo Code

class Hello//from   ww w . j a  v  a2s .c o  m
{
   public static void Main()
   {
      string answer;
      System.Console.WriteLine("Do you want me to write the two words?");
      System.Console.WriteLine("Type y for yes; n for no. Then <enter>");
      answer = System.Console.ReadLine();
      if (answer == "y")
         System.Console.WriteLine("Hello World!");
      System.Console.WriteLine("Bye Bye!");
   }
}

Result


Related Tutorials