|
|
|
| Web Hosting Guide |
![]() ![]() |
Lesson #1 - Introduction To C#, Console Application |
Apr 27 2006, 10:18 PM
Post
#1
|
|
|
Newbie [ Level 1 ] 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)
|
|
|
|
Sep 8 2008, 03:38 PM
Post
#2
|
|
|
Newbie [ Level 1 ] 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 |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
1 | oval | 1,700 | 21st February 2010 - 10:53 AM Last post by: iG-James |
|||
![]() |
14 | vicky99 | 2,644 | 26th January 2010 - 12:08 AM Last post by: iG-Bradley P |
|||
![]() |
2 | turbopowerdmaxsteel | 7,994 | 4th January 2010 - 07:29 AM Last post by: iG-v_tarasu |
|||
![]() |
1 | turbopowerdmaxsteel | 8,385 | 9th December 2009 - 10:22 AM Last post by: iG-imran |
|||
![]() |
3 | turbopowerdmaxsteel | 14,482 | 9th November 2009 - 08:28 PM Last post by: iG-smsma |
|||
![]() |
1 | Soviet Rathe | 113 | 4th November 2009 - 10:22 AM Last post by: yordan |
|||
![]() |
1 | terrence123 | 123 | 21st October 2009 - 01:40 PM Last post by: yordan |
|||
![]() |
3 | oval | 9,922 | 22nd September 2009 - 09:56 AM Last post by: iG-kushal |
|||
![]() |
1 | t3jem | 3,854 | 20th August 2009 - 01:01 PM Last post by: iG-Patrick Coffman |
|||
![]() |
2 | turbopowerdmaxsteel | 9,661 | 23rd July 2009 - 06:02 AM Last post by: iG-omar shan |
|||
![]() |
10 | t3jem | 3,739 | 20th May 2009 - 01:39 PM Last post by: iG-bubuzzz |
|||
![]() |
3 | Ashraful | 837 | 29th April 2009 - 11:17 AM Last post by: yordan |
|||
![]() |
12 | Archimedes | 1,568 | 11th April 2009 - 04:24 PM Last post by: yordan |
|||
![]() |
4 | t3jem | 2,224 | 22nd January 2009 - 08:38 PM Last post by: iGuest |
|||
![]() |
5 | tansqrx | 8,139 | 30th November 2008 - 04:17 AM Last post by: iG-Mark |
|||
|
Lo-Fi Version | Time is now: 21st March 2010 - 01:10 PM |
© 2010 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Apr 27 2006, 10:18 PM






