Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Lesson #1 - Introduction To C#, Console Application
oval
post Apr 27 2006, 10:18 PM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 3
Joined: 26-April 06
From: Texas
Member No.: 13,037



This tutorial will help get you started with C# Sharp. These tutorials will assume that you are using the Visual Studio environment. If you are just curious to test out some code, then you can copy and paste this code into your CS file, however, before doing so, make sure to name your project the same as the namespace on the code. But since this first program is fairly easy, it will not hurt to type it out. It is fairly easy and short. Also, this program is highly commented so it should be easy to follow along. Comments will have 2 forward slashes before them '//' trailing with the comment.

Well before looking at the code, I just want to summarize what the following lines of code will do.

Console.WriteLine(); <----- Writes a string of characters on the console in it's own line.

So writing Console.WriteLine("Hello World"); would result in Hello World displaying on your console and have the cursor move to the next line down.

Console.Write("Hello World"); would also display Hello World however the cursor would be next to the word and not the line below.

Console.ReadLine(); <------ This nifty method will allow you to take in user input. Whether the user input is numeric or alphabetic, it will take the input as a string or text. So you cannot use it in any mathematical operations right away. That is if the user was to enter 5 and you want to add 4 to that 5, you could not, right off the bat anyway. However we will go into that later.

Okay, now observer the code below:
using System;

CODE

==================== BEGIN C# CODE =====================================

namespace testProg

{

     ///<summary>

     /// Test Programming

     ///</summary>

     class helloProg

     {



            [STAThread]

            static void Main(string[] args)

            {

                 //Declare a String variable. Name it userName

                 string userName;

                 Console.Write("Console Asks - Please Enter your Name: ");

                 //Place the user input into the variable userName with
                 //Console.ReadLine()

                 userName = Console.ReadLine();

                 //Skip a line for nicer formatting

                 Console.WriteLine("");

                //On the next line, display the input.

                 //{0} is where the variable value will go. It

                 //is followed by a comma and variable name userName

                 Console.WriteLine("Hello {0}!", userName);

                 Console.WriteLine("Press Enter to Continue");

                 //The Console.Readline will pause the program until you

                 //press [ENTER]. Then it will exit.

                 Console.ReadLine();



            } //end main

     } //end class

} //end namespace

=========================== END C# CODE ================================


Okay aside from the information I provided before the code, I think the comments explain pretty much what is going on within this program. However, I want to further elaborate how we placed the user input into the variable userName. By setting first we declared userName as a string (i.e. string userName;) Later in the program, we said userName is equal to what the user enters, userName = Console.ReadLine(); This is what did the trick. now we just output user name in one of our Console.WriteLine's and Voila. Modify the variables, add lines and variables and get acquainted with it yourself. I'll be back soon to provide another lesson.

By the way, I hope I am able to upload my attachment. The code on this one looks kinda sloppy. It's in .pdf format.
Attached File(s)
Attached File  LESSON_ONE.pdf ( 8.81k ) Number of downloads: 64
 
Go to the top of the page
 
+Quote Post
iGuest
post Sep 8 2008, 03:38 PM
Post #2


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 0
Joined: 1-November 07
Member No.: 25,869



c# console application question (card game)
Lesson #1 - Introduction To C#

I want to know about how to do about the following question.


Create a simple GUI application to simulate a two player Game. A detailed description of the requirements follows:

Player 1 makes a guess. It compares with a pseudo random number. If they match, player 1 wins and the game is over. In case of a mismatch, player 1 passes the random number to player 2 and a challenge begins. Player 2 also makes a guess and then compares the number with the random number it has received. If the numbers match, player 2 wins the challenge and the game is over. In a case of a mismatch player 2 discards the random number and generates another random number to compare with the guessed number. If they match player 2 wins the challenge and the game is over. In the case of a mismatch, player 2 passes the random number to player 1 and a challenge begins. The sequence is to be repeated till a winner emerges.

Create player 1 using .Net technology and player 2 using Java technology to simulate the game and use a XML file to establish the communication between the players. You should be able to display the current player in both interfaces with appropriate messages to display the winning player and to indicate the game is over.



-reply by Buddhika
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Lesson #2 - Switch Statement In C#(1)
  2. Installing Vb.net(3)
  3. C# Tutorial : Lesson 1 - Hello World Program(0)
  4. C# Tutorial : Lesson 2 - Variables & Operators(0)
  5. C# Tutorial : Lesson 3 - Programming Constructs(1)
  6. C# Tutorial : Lesson 4 - Object Oriented Programming(2)
  7. C# Tutorial : Lesson 5 - Encapsulation & Abstraction(0)
  8. C# Tutorial : Lesson 6 - Creating Value Types & Reference Types - Part I(0)
  9. C# Tutorial : Lesson 7 - Creating Value Types & Reference Types - Part II(1)
  10. C# Tutorial : Lesson 8 - Functions/methods(0)
  11. C# Tutorial : Lesson 9 - Constructors & Destructors(0)
  12. Lesson1 :introduction To Visual Basic(2)
  13. Creating Your First Application(1)


 



- Lo-Fi Version Time is now: 3rd December 2008 - 11:38 PM