1. Display series of numbers (1,2,3,4, 5....etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESCAPE key).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace lrn2CSharp1
{
class Program
{
static void Main( string[ ] args )
{
for ( int i = 0; ; i++ )
{
if ( Console.KeyAvailable && keyPressHandler( Console.ReadKey( true ) ) ) break;
Console.Write( i + " " );
Thread.Sleep( 250 );
}
}
protected static Boolean keyPressHandler( ConsoleKeyInfo input )
{
if ( input.Key == ConsoleKey.Escape ) return true;
return false;
}
}
}
posted by dharh 7:13 PM Feb 10th, 2008