Read user selection from keyboard : Console Read « Development « C# / CSharp Tutorial






using System;

class MainClass
{
  public static int Main(string[] args)
  {
    Console.WriteLine("1 = A \n 2 = B \n3 = C\n"); 
    Console.Write("Please select your implementation language:"); 

    // Get choice.
    string s = Console.ReadLine(); 
    int n = int.Parse(s);
  
    switch(n) 
    {
      case 1:
        Console.WriteLine("\nGood choice!  C# is all about managed code.");
        break;
  
      case 2:
        Console.WriteLine("\nLet me guess, your maintaining a legacy system?");
        break;
    
      case 3:
        Console.WriteLine("\nVB.NET:  It is not for just kids anymore...");
        break;
    
      default:
        Console.WriteLine("\nWell...good luck with that!");
        break;
    }
    return 0;
  }
}
1 = A
 2 = B
3 = C

Please select your implementation language:1

Good choice!  C# is all about managed code.








14.6.Console Read
14.6.1.Reading Console Input
14.6.2.Read a character from the keyboard.
14.6.3.Input from the console using ReadLine().
14.6.4.Read a string from the keyboard, using Console.In directly
14.6.5.Read input from console
14.6.6.Read user selection from keyboard
14.6.7.How to read a character entered using the keyboard
14.6.8.How to read a string entered using the keyboard