-2

I have a problem! When I run this code in c# console application:

class Program  
{ 
    static void Main(string[] args)        
    {    
        Console.WriteLine("Press any key to exit.");            
        Console.Readkey();
    }
} 

.. it doesn't take effect and the program automatically closes ... What to do?

Manfred Radlwimmer
  • 12,469
  • 13
  • 47
  • 56

2 Answers2

-1

There is a typo in your code so you are probably running an older build

Change

Console.Readkey

To

Console.ReadKey
Jan-Fokke
  • 2,859
  • 1
  • 14
  • 36
-3

Add following Code instead of Console.ReadKey() It will hold the screen on monitor.

Console.ReadLine();
Govind Tupkar
  • 266
  • 2
  • 5
  • Why is ReadLine any better than ReadKey? – Alfie Goodacre Oct 27 '16 at 10:26
  • So will `Console.ReadKey()` if using the correct capitalisation which the OP has not done. – Steve Oct 27 '16 at 10:26
  • because Readkey() accept the Character and return ASCII value of that character . And ReadLine() accept the String and return the string as well. – Govind Tupkar Oct 27 '16 at 10:34
  • 1
    @GovindTupkar but how is that helpful? The OP's question clearly has this line `Console.WriteLine("Press any key to exit.");` not only do they not care about getting anything returned, they specifically want *one* character – Alfie Goodacre Oct 27 '16 at 10:39