Console.ReadKey Method In C#

In this article, I will explain you about Console.ReadKey method in C#.
  • 12705


Console programs read input and write output. For reading purpose we can also use Console.ReadKey method. Console.ReadKey method is used to obtain the key pressed by the user in the console window. This method accept the character and also return character.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication11


    class Program


        static void Main(string[] args)


            // Write to console window.

            ConsoleKeyInfo s;

            Console.WriteLine("-----------press insert----------");

             s = Console.ReadKey();

            if (s.Key == ConsoleKey.Insert)


                Console.WriteLine("You pressed insert");








ConsoleKeyInfo is used to describes the console key that was pressed.

The output of following program



© 2018 DotNetHeaven. All rights reserved.