Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
N

ncarey

@ncarey
About
Posts
1
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • can you figure out why does this piece of code stop every 40 iterations instesd of 20? Hint: you have to hit enter to continue
    N ncarey

    Better to add to your toolbox of utility/helper methods:

    static bool WaitForKeyPress()
    {
    return WaitForKeyPress( ConsoleKey.Escape ) ;
    }

    static bool WaitForKeyPress( ConsoleKey quit_key )
    {
    ConsoleKeyInfo keypress ;
    bool fQuit = false ;

    FlushConsoleInputBuffer() ;
    WriteConditionalEOL() ;
    Console.Write( "Press ESC to quit or any other key to continue> " ) ;

    keypress = Console.ReadKey( false );
    fQuit = ( keypress.Key == quit_key ? true : false );

    WriteConditionalEOL();

    return fQuit;

    }

    private static void FlushConsoleInputBuffer()
    {
    while ( Console.KeyAvailable )
    {
    Console.ReadKey( true ); // true: don't echo input
    }
    return;
    }

    private static void WriteConditionalEOL()
    {
    if ( Console.CursorLeft > 0 )
    {
    Console.WriteLine();
    }
    return;
    }

    Clever Code question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups