Hello World - Console Application
http://www.csharpfriends.com
World's Greatest C# Community    
Home Articles C# Forums Books C# Syntax C# Spec C# Jobs free Source Code Advertise About
 

Control Panel

[ Sign In / register ]
Points   
Notes 
My Forums
My Tutorials
My Profile

Resources

Learn
 Articles
 QuickStarts
 C# Spec
 Whitepapers
 Tools
 Class Browser
 C# Code Generator
 Links
 Misc Rss Feeds
 Code Highlight
 411 Directory
 FREE magazines
 freevb.net

Reviews
  ASP.NET Hosting

Source Code
 Get Version 1.0



C# Consulting
sql server forums
Chapter:   UnCategorized
Current Lesson:
Hello World - Console Application
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  C# Syntax Reference Card [next Lesson]  Delegates And Events - The Uncensored Story
Hello World - Console Application
  by: Salman Ahmed

Beginning C# - So you want to learn about the C# eh?

Lets start you off with a console program for a change, and without further delay here is your "Hello, World!" program.

using System;

namespace CSharpFriends
{
    /// 
    /// Summary description for Class1.
    /// 
    class Class1
    {
        /// 
        /// The main entry point for the application.
        ///     
        static void Main(string[] args)
        {

            Console.WriteLine("Hello, World");    
        
        }
    }
}
Lessons to be learned:

Comments in C# can be one of the following:
// I am a comment
/* I 

   am
   a
   comment
*/

The Main method controls the start and ending of the program. All object creation and method invocation goes here. As you can tell, Main() is returning void, it can also return int. Main's parameter is a string array that represents the command-line arguments you enter while compiling. We will get into the details of that in another tutorial hopefully.

Console.WriteLine is the Response.Write but for console applications that outputs to standard out. The two methods are Write and WriteLine, the latter displays the string followed by a newline.

The using System; statement allows you to become a lazy coder, without it you will need to fully qualify your statements such as System.Console.WriteLine

Hopefully you have hacked the above into notepad and saved it as Hello.cs..but now what? You need a short course in compilation! There are two files that you will have to make here:

Source file (the one you typed in notepad): Hello.cs

Executable file: Hello.exe

To complie, simply type: csc Hello.cs

If the command prompt did not recognize csc, you either have not installed the SDK (oops!) or you need to put csc in your environmental path. On my system, the compiler (csc) is found in: C:\WINNT\Microsoft.NET\Framework\v1.0.3705

On Win2k, you will have to go to control panel -> System -> Advanced -> Environmental Variables then scroll down on the bottom window and look for path. Edit path and add the directory where csc is stored (make sure to search on your system for it as it may be different from mine, start a new command prompt as adding a new environmental variable will not get loaded in).

Once compiled, type: Hello.exe to view the execution of the program!

1 


Build Your Own ASP.NET Website Using C# & VB.NET

Chapter:  UnCategorized
Current Lesson:
Hello World - Console Application
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  C# Syntax Reference Card [next Lesson]  Delegates And Events - The Uncensored Story



Today's Top Movers
vulpes 3766
MadHatter 2056
jal 675
muster 623
George2 545

Yesterday Top Movers
shakti sin.. 9
MadHatter 3
Al_Pennywo.. 2
C#fanatic 2
simboy 1



Monthly Leaders
vulpes 3766
MadHatter 2096
jal 675
muster 623
George2 545

Top Members
mosessaur 18457
Rincewind 7074
stanleytan 6995
Gsuttie 6046
juliet 4679

Great Offers
.net hosting
Go To My Pc
Remote Pc Control
zonealarm
spam blocker
web hosting directory
ad server   C#
snadtech GoToMyPc

Top of Page

Advertise | About | Link To Us | Privacy Notice Copyright © 2003 - 2005 CSharpFriends.com  All Rights Reserved  Visual C# Developer Center