faqts : Computers : Programming : Languages : C#

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 12 people (75%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

C#: Program: Create: Simple: How to write a program in C# which displays 'Hello World'?

Jan 10th, 2004 12:38
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 11 September 2003 - 00:41 pm ------------------

C#: Program: Create: Simple: How to write a program in C# which 
displays 'Hello World'?

---

Steps: Overview:

 1. Possibly download and install the
    free Microsoft .net framework SDK,
    http://www.microsoft.com/downloads/details.aspx?familyid=4fe5bdb5-
c7a7-4505-9927-2213868a325b&languageid=f49e8428-7071-4979-8a67-
3cffcb0c2524&displaylang=en

    or

    use Visual Studio .net

    When installed, the C# compiler

      csc.exe

     can usually be found in a directory
     similar to:

     C:\WINDOWS\Microsoft.NET\Framework\v1.0

 2. Type the program in your favorite text editor

--- cut here ---------------------------------------------------------

using System;

class HelloWorld {
 static public void Main() {
  System.Console.WriteLine( "Hello World" );
 }
}

--- cut here ---------------------------------------------------------

 3. Your program should so contain the 'main' method

 4. Save this file with extension .cs

     e.g.

      HelloWorld.cs

 5. Compile with

     csc.exe HelloWorld.cs

 6. If compiled successfully this will create
    (in the same directory) a file:

     HelloWorld.exe

 7. Run with

     HelloWorld

 8. That will show on the console command line:

     Hello World

---

Here a typical screen of your console:

+---------------------------------------------------------------------+
|[C:\TEMP] cd c:\WINDOWS\Microsoft.NET\Framework\v1.0.2914            |
|                                                                     |
|[C:\TEMP] csc.exe c:\temp\HelloWorld.cs                              |
|                                                                     |
|Microsoft (R) Visual C# Compiler Version 7.00.9254 [CLR version v1.0]|
|Copyright (C) Microsoft Corp 2000-2001. All rights reserved.         |
|                                                                     |
|[C:\TEMP] HelloWorld.exe                                             |
|Hello World                                                          |
+---------------------------------------------------------------------+

---
---

Internet: see also:

---

Joe Grip's interactive guides to programming
http://www.joegrip.com/seeit.html

---

Microsoft:Visual Studio: Project: Create: New: Can you give overview? 
[console / windows / Internet]
http://www.faqts.com/knowledge_base/view.phtml/aid/28187/fid/1600

----------------------------------------------------------------------