C# Hello World Tutorial
In this chapter you will learn:
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:
- What are variables
- Syntax to define C# variables
- Example for C# variables
- C# program for variable definition