Difference between revisions of "Console.Read Console.Write Demo"
Line 61: | Line 61: | ||
//Pause and wait for the user to press a key | //Pause and wait for the user to press a key | ||
Console.ReadKey(); | Console.ReadKey(); | ||
+ | </csharp> | ||
+ | |||
+ | <csharp> | ||
+ | using System; | ||
+ | using System.Collections.Generic; | ||
+ | using System.Text; | ||
+ | |||
+ | namespace ConsoleRead | ||
+ | { | ||
+ | class Program | ||
+ | { | ||
+ | static void Main(string[] args) | ||
+ | { | ||
+ | string strName; //Declare a string object | ||
+ | |||
+ | Console.Write("What is your name? "); | ||
+ | strName = Console.ReadLine(); //set strName value equal to what the user typed | ||
+ | |||
+ | Console.Write("Hello " + strName); | ||
+ | |||
+ | //Pause and wait for the user to press a key | ||
+ | Console.ReadKey(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
</csharp> | </csharp> |
Revision as of 04:21, 11 September 2007
Start Visual Studio
Select Console Application and Name the Project
You should see the following Code in the project
<csharp>
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleRead {
class Program { static void Main(string[] args) { } }
} </csharp>
Add the following code to make our new project similar to the HelloWorld porject
<csharp> using System; using System.Collections.Generic; using System.Text;
namespace ConsoleRead {
class Program { static void Main(string[] args) { Console.Write("Hello"); } }
} </csharp>
To build the project Select
or
You should a black console window flash on the screen and really quicly display the word 'Hello'
Add the following lina after the Console.Write Line
<csharp> Console.Write("Hello");
//Pause and wait for the user to press a key Console.ReadKey();
</csharp>
<csharp> using System; using System.Collections.Generic; using System.Text;
namespace ConsoleRead {
class Program { static void Main(string[] args) { string strName; //Declare a string object Console.Write("What is your name? "); strName = Console.ReadLine(); //set strName value equal to what the user typed Console.Write("Hello " + strName);
//Pause and wait for the user to press a key Console.ReadKey(); } }
} </csharp>