Thursday, May 22, 2014

C# Programming Tutorial ( Part 1 )

A first simple program

/*
This is a simple C# program. Call this program Example.cs.
*/
using System;
class Example {
// A C# program begins with a call to Main().
static void Main() {
Console.WriteLine(“A simple C# program.”);
}
    }

The primary development environment for C# is Microsoft’s Visual Studio. To compile all of the programs in this book, including those that use the new C# 4.0 features, you will need to use a version of Visual Studio 2010 (or later) that supports C#. Using Visual Studio, there are two general approaches that you can take to creating,
compiling, and running a C# program. First, you can use the Visual Studio IDE. Second, you can use the  command-line compiler, csc.exe. To actually run the program, just type its name of the program  on the command line.



Explanation

using System;
This line indicates that the program is using the System namespace. In C#, a namespace defines a declarative region. Through the use of namespaces, it is possible to keep one set of names separate from another. In essence, names declared in one namespace will not conflict with names declared in a different namespace. The namespace used by the program is System, which is the namespace reserved for items associated with the .NET Framework class library, which is the library used by C#. The using keyword simply states that the program is using the names in the given namespace.