stopwatch
game pic
//===========================================
// Uses stopwatch class to time
//    Manipulates number and arrays
//    Does nonsense operations
//
using System;
using System.Diagnostics; // For Stopwatch

class Program
{
   static void Main()
   {
      int x = 0;
      int[] myNums = new int[1000000];
      int limit;

      // instantiate (create) a stopwatch object called "st"
      Stopwatch st = new Stopwatch();

      // get number from user
      limit = GetNumber(10000, 1000000);

      // start timer
      st.Start( );

      // loop limit times (from user), write out every 5,000th
      do
      {
        // go waste time
        DoStuff(ref x, myNums);

        // life signs monitor
        if ( x % 5000 == 0 )
           Console.Write( "\nCycle: " + x.ToString() + " " );

        // leave the loop?
        if ( x >= limit )
           break;
      } while ( true );

      // stop timer and report
      st.Stop( );

      Console.WriteLine( "\nElapsed Time = " + st.Elapsed.ToString( ) + " seconds." );
      Console.ReadKey();
   }

   ////////////////////////////////////////////////////////
   // prompt and get a number between min and max exclusive 
   // max  has a default which also makes it optional( must be last)
   private static int GetNumber(int min, int max=40000) 
   {
      int num;
      bool ok;
      do
      {
         Console.Write("Enter a number bigger than " 
                      + min.ToString("n0") 
                      + " and less than " 
                      + max.ToString("n0") + " : ");
         ok = int.TryParse(Console.ReadLine(), out num);
      } while(ok == false || num>max || num < min);
      return num;
   }

   ///////////////////////////////////////////////////////
   // stores and increments number
   static void DoStuff( ref int num, int[] numList )
   {
     // waste time
     long result;

     // put into array and increment
     numList[num] = num++;

     // waste time with incremented number
     double root = Math.Sqrt(Math.Sqrt(num));
     if( (result = Waste(numList, num)) % 10000 == 0)
        Console.WriteLine("\nSum: " + result.ToString("n0"));
   }

   ////////////////////////////////////////////////////
   // waste time
   static long Waste(int[] list, int size)
   {
      long sum = 0;
      try
      {
         for (int i = 0; i < size; i++)
         {
            checked { sum += list[i]; }
         }
      }
      catch (Exception ex)
      {
         Console.WriteLine("\nError: " + ex.Message);
         return 0;
      }
      return sum;
   }
}