C# Hello World Tutorial

In this chapter you will learn:

  1. Your first C# Program
  2. Source Code for your first C# Program
  3. Compiling and running the Program

Description

Let's start by compiling and running the simplest possible C# program.

Source Code

Type the following into a text editor, and save it as First.cs.


using System; //from   w w  w  .j  a v  a  2s.  c o m
           
public class MyFirstClass 
{ 
   static void Main() 
   { 
      Console.WriteLine("Hello from java2s.com."); 
      Console.ReadLine(); 
      return; 
   } 
}  

Compiling and running

You can compile this program by simply running the C# command - line compiler ( csc.exe ) against the source file, like this:

csc First.cs

Compiling the code produces an executable file named First.exe.


csc First.cs  // w ww.j  av  a 2 s.  c  o  m
Microsoft (R) Visual C# 2010 Compiler version 4.0.20506.1  
Copyright (C) Microsoft Corporation. All rights reserved. 
                         
First.exe  
Hello from java2s.com.    

Next chapter...

What you will learn in the next chapter:

  1. What are variables
  2. Syntax to define C# variables
  3. Example for C# variables
  4. C# program for variable definition
Home »
  C# Tutorial »
    C# Language »
      C# Hello World
C# Hello World Tutorial
C# Variables