"C# for the Completely Uninitiated: Tutorial #6 Source Code Listings"

C# for the Completely Uninitiated

Tutorial #6: Source Code Listings

Back to Tutorial #6


Program xwrite.cs


01	 using System;
02
03	 class Program{
04
05	   static void Main(){
06
07	      int x=0;
08
09	      if(x > 0){
10
11	         Console.WriteLine("The number x is greater than zero.",  x);
12         
13
14	      } else {
15
16	         Console.WriteLine("The condition \"x > 0\" was not met.");
17
18
19	      }//end if
20
21	      Console.ReadLine();
22
23	   }//end method Main
24
25	}//end class Program



Program google.cs


using System;

class Program{

    static void Main(){

          string employer = "";
          Console.Write("Who agreed to interview you? ");
          employer = Console.ReadLine().Trim().ToLower();

          if(employer=="google"){

              Console.WriteLine("You go, Googlemeister!");

          }else if(employer=="yahoo"){

       	      Console.WriteLine("You're a rowdy Yahooligan!");

          }else if(employer=="cisco"){

	      Console.WriteLine("So, Cisco seems interested, eh?");
 
          }else{

	     Console.WriteLine("Let's hope Bill Gates likes you...");
  
          }//end if

          Console.ReadLine();

    }//end method Main

}//end class Program


Program socks.cs


using System;

class Program{

    static void Main(){

        string sSockColor = "";

        Console.Write("Please enter red, blue, green, or black for sock color: ");

        sSockColor = Console.ReadLine();

        switch(sSockColor.Trim().ToLower()){

        case "red":
            Console.WriteLine("Feeling irritable today, are we?");
            break;

        case "blue":
            Console.WriteLine("Awww, are we feeling a bit blue today?");
            break;

        case "green":
            Console.WriteLine("What is this, St. Patrick's Day!?");
            break;

        case "black":
            Console.WriteLine("You need to add some color to your ensemble.");
            break;

        default:
            Console.WriteLine("You shouldn't be allowed to dress yourself...");
            break;

        }//end switch statement
   
    }//end method Main

}//end class Program



Program equalstwo.cs

using System;

class Program {
    
    static void Main(string[] args) {
    
        int x = 2, y = 2;

        if (x == 2 || y == 2) {

            Console.WriteLine("Either x or y (or perhaps both) is equal to two.");

        } else {

            Console.WriteLine("Neither one of the variable holds the value 2.");

        }

        Console.WriteLine("\nPress the Enter button to exit program");
        Console.ReadLine();

    }
}


Program kingsharp.cs


using System;

class Program{

    static void Main(){

        int x = 0;

        try{
               Console.Write("Brag how many times? (specify 2 to 10): ");

               x = Int16.Parse(Console.ReadLine());

               if(x < 2){ x=2; }

               if(x > 10){ x=10; }

               Console.WriteLine();

               for(int i=1; i<=x; i++){

                   Console.WriteLine("C#, King of Programming Languages!");

               }//end for loop

               Console.Write("\nPlease press Enter to end program ");


           } catch (Exception e) {

               Console.WriteLine(e.Message);

           }

           Console.ReadLine();

    }//end method Main

}//end class Program



Program brag10.cs


using System;

class Program{

    static void Main(){

        int lineNum = 0;

        Console.WriteLine();

        for(int i=0;i<10;i++){
            lineNum = i+1;
            Console.WriteLine("C# Rules!   (line # " + lineNum.ToString() + ")");
        }//end for loop

        Console.Write("\nPress the Enter key to end program ");
        Console.ReadLine();

    }//end Main

}//end class Program

Program fiftybyfives.cs


using System;

class Program{

    static void Main(){

        Console.WriteLine();

        for(int i=0;i<=50;i+=5){
            Console.Write(i.ToString() + "\t");
        }//end for loop

        Console.Write("\n\nPress the Enter key to end program ");
        Console.ReadLine();

    }//end Main

}//end class Program


Program blastoff.cs


using System;

class Program{

    static void Main(){

        Console.WriteLine();

        Console.WriteLine("\nTower to shuttle: \"We're showing all systems are a go...\"");
        System.Threading.Thread.Sleep(2500);

        Console.WriteLine("\nShuttle to tower: \"Roger that!  We're green across the board here...\"");
        System.Threading.Thread.Sleep(2500);

        Console.WriteLine("\nTower to shuttle: \"Roger, shuttle.  Initiating countdown...\"\n");
        System.Threading.Thread.Sleep(2500);

        for(int i=10;i>0;i--){
            Console.Write(i.ToString() + "\t");
            System.Threading.Thread.Sleep(750);
        }//end for loop

        Console.WriteLine("Blastoff!!!\n");

        Console.Write("\n\nPress the Enter key to end program ");
        Console.ReadLine();

    }//end Main

}//end class Program


Program mobius.cs


using System;

class Program{

    static void Main(){

        for(int i=0; i>-1; i++){
            //Everybody sing: "this is the loop that never ends..."
            Console.WriteLine("Loop iteration #" + i.ToString());
        }

    }//end Main

}//end class Program


Program dowhile.cs


using System;

class Program
{
	static void Main()
	{
            int x = 0;

            Console.WriteLine(); //skip line, for readability

            do{

                 x++;
                 Console.Write(x.ToString() + "\t");
                 System.Threading.Thread.Sleep(500);

            } while (x < 10);

            Console.WriteLine();

	}
}//end class Program


Program whiletest.cs


using System;

class Program
{
	static void Main()
	{
            int x = 0;

            Console.WriteLine(); //skip line, for readability

            do{

                 
                 Console.Write("I can't believe it's not butter!");
                 

            } while (x != 0);

            Console.WriteLine();

	}
}//end class Program


Program whiletest2.cs


using System;

class Program
{
	static void Main()
	{
            int x = 0;

            Console.WriteLine(); //skip line, for readability

            while (x!=0){

                 
                 Console.Write("I can't believe it's not butter!");
                 

            } 

            Console.WriteLine();

	}
}//end class Program