Check the string read from console - CSharp Language Basics

CSharp examples for Language Basics:Console

Description

Check the string read from console

Demo Code

using System;/*from ww w  . j  ava  2 s  . c  o m*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Input
      Console.Write("Enter password: ");
      string enteredPassword = Console.ReadLine();
      // Password check
      if (enteredPassword == "friend")
      {
         Console.WriteLine("Password is OK, please enter");
      }
      else
      {
         Console.WriteLine("Incorrect password");
      }
   }
}

Result


Related Tutorials