|
|
In this lesson we will write our first C# program. But, before doing so we need to understand some basics.
C# programs can be written in any text editor, but it is recommended that you use Visual Studio 2010.
C# program files can be saved with any extension, it is recommended that you save them with .cs extension. Visual Studio 2010 does this automatically.
Enough theory! now let's write our C# Hello World program:
Program Code:using System;
// System namespace similar to a package in Java
public class HelloWorld {
public static void Main(){
// the Main function starts with capital M
// and needs not to have the famous args []
Console.WriteLine("Hello World!");
}
}
You must be glad to see that the above code is very identical to Java and C++. The above code, when compiled and run, simply prints the words "Hello World!" to the console.
It may be noted that just like Java and C++, C# is case sensitive. Additionally, as we have in Java, everything in C# has to be inside a class and there is no semicolon at the end of the
class. However, unlike Java, name of the class and the name of the file in which it is saved needs not to match up. You are free to choose any extension for the file, but it is good to use the
extension '.cs'. Like C++ and Java C# also supports single line and multi-line comments. The 'using' keyword in the first line is just a synonym of the 'import' keyword used in Java.
Next >>> Lesson No. 5: C# Data types
|
|