c# console code
Differences from Windows Form Programs: NOT event-driven Class has a single static Main() method (actually so does Form) -all methods in the class will be static (* see dotnetperls) Other classes can be static or non-static as needed -a class with a single instance is called a "singleton" I/O System.Console.Write(); System.Console.WriteLine(); System.Console.Read(); System.Console.ReadLine();


   // wyatt
   // says hello to the world
   // adds 2 integers and outputs answer - note use of "ToString()"

   class HelloWorld // a class acts as a container for code
   {
      static void Main()
      {
         // output text to the screen - use the console class
         System.Console.WriteLine( "Hello World!" );
         System.Console.WriteLine( "7 + 4 = " +  7 + 4.ToString() ); //whoops - 74!!
         System.Console.WriteLine( "7 + 4 = " + (7 + 4).ToString() );
         System.Console.ReadKey();
      }
   }   
   

   // simple strings
   class Program // a class acts as a container for code
   {
      static void Main()  // every program needs a method called 'main'
      {
         string firstName;
         string lastName;

         System.Console.WriteLine("Hey you!");

         System.Console.Write("Enter your first name: ");
         firstName = System.Console.ReadLine();

         System.Console.Write("Enter your last name: ");
         lastName = System.Console.ReadLine();

         System.Console.WriteLine("Your full name is {0} {1}.", firstName, lastName);
             // or...
         System.Console.WriteLine("Your full name is " + firstName + " " + lastName + ".");
         System.Console.ReadKey();
      }
   }   
 


   // wyatt
   // gets and adds 2 integers and outputs answer - note use of "ToString()"

   class HelloWorld // a class acts as a container for code
   {
      static void Main()
      {
         int num1, num2;
         bool ok;

         // get nums
         num1 = int.Parse(Console.ReadLine()); // aborts on bad input
         ok = int.TryParse(Console.ReadLine(), out num2);  // should check ok

         // output to the screen - use the console class
         System.Console.WriteLine( num1 + " + " + num2 +  " = " + (num1+num2).ToString() );
         System.Console.ReadKey();         
      }
   }   
   


   // Rob Miles
   //
   // IPO

   using System;
   class GlazerCalc // a class acts as a container for code
   {
       static void Main()  // every program needs a method called 'main'
       {
           double width, height, woodLength, glassArea;
           string widthString;

           // get input
           widthString = Console.ReadLine();
           width = double.Parse(widthString);
           height = double.Parse( Console.ReadLine() );

           // process
           woodLength = 2 * (width + height) * 3.25;
           glassArea = 2 * (width * height);

           // output
           Console.WriteLine("The length of the wood is " + woodLength + " feet");
           Console.WriteLine("The area of the glass is " + glassArea + " square metres");
           Console.ReadKey();           
       }
   }   
   


      #define DEBUG  // used to allow conditional compilation/execution
      
      // TO CALL
      long? x = SumRange(1,2100000000); 
   
   
      ///////////////////////////////
      // wyatt
      //    accepts 2 ints
      //    loops from start to end
      //       calculates the sum
      //    return a decimal sum         
      // example:
      //   1 to 500 million
      //   sum is 125,000,000,250,000,000 - 125 quadrillion, 250 million
      //////////////////////////////
      private static long? SumRange(int start, int end)
      {
         // use long to be able to hold LARGE sums
         // make nullable (?) to be able to return null on error
         long? sum = 0;

         try // protect
         {
            #region LoopToSum
            // loop from start to end accumulating the sum
            for (int i = start; i <= end; i++)
            {
               checked // throws an exception upon overflow
               {
                  sum += (long)i;
               }
            }
            #endregion
         }     
     
         catch (Exception ex)  // error
         {
            #if DEBUG // pre-processor directive: 
                      // relies on #define DEBUG at "very top of file"
               Console.WriteLine(ex.Message);
            #endif 
            return null; // error return (can't use 0, or -1 as those might be real
         }

         // give back the calculated sum
         return sum;
      }