Introduction of C#

C# has been developed by Microsoft Corporation within the .NET team, and approved as a standard by ECMA and ISO/IEC later. C#, which is one of the programming languages designed for the Common Language Infrastructure, is intended to be a simple, modern, object-oriented and common-purpose programming language

There are some fundamental elements that all C# executable programs have and that’s what the C# programmer need to understand. After reviewing the code in below, I’ll explain the basic concepts that will follow for all C# programs we will develop.

// Namespace Declaration
using System;

// Program start class
class Hello
{
// Main begins program execution.
static void Main()
{
// Write to console
Console.WriteLine(“Hello to All C# Programmers”);
}
}

First of all, we should talk about case-sensitive of C#. The word “Main” is not as same as its lower case spelling, “main”. They are different identifiers.

The namespace declaration, “using System;”, indicates that we are referencing the System namespace. Namespaces contain groups of code that can be called upon by C# programs. With the “using System;” declaration, we are telling the program that it can reference the code in the System namespace without pre-pending the word System to every reference.

The class declaration, class Hello, contains the data and method definitions that the program uses to execute. A class is one of a few different types of elements that the program can use to describe objects. This particular class has no data, but it does have one method. This method defines the behavior of this class.

The one method within the Hello class present what this class will do when executed. The method name, “Main”, is reserved for the starting point of a program. “Main” is often called the “entry point” and if we ever receive a compiler error message saying that it can’t find the entry point, it means that you tried to compile an executable program without a “Main” method. In addition, every method must have a return type. In this case it is void, which means that Main does not return a value. Every method also has a parameter list following its name with zero or more parameters between parenthesis. For simplicity, we did not add parameters to Main.

The Main method specifies its behavior with the Console.WriteLine(…) statement. Console is a class in the System namespace. WriteLine(…) is a method in the Console class. We use the “.”, dot, operator to separate subordinate program elements. Note that we could also write this statement as System.Console.WriteLine(…). This follows the pattern “namespace.class.method” as a fully qualified statement. Had we left out the using System declaration at the top of the program, it would have been mandatory for us to use the fully qualified form System.Console.WriteLine(…). This statement is what causes the string, “Hello to All C# Programmers” to print on the console screen.

Observe that comments are marked with “//”. These are single line comments, meaning that they are valid until the end-of-line. If you wish to span multiple lines with a comment, begin with “/*” and end with “*/”. Everything in between is part of the comment. Comments are ignored when your program compiles. They are there to document what your program does in plain English (or the native language you speak with every day).

All statements end with a “;”, semi-colon. Classes and methods begin with “{“, left curly brace, and end with a “}”, right curly brace. Any statements within and including “{” and “}” define a block. Blocks define scope (or lifetime and visibility) of program elements.

References:
C# Language Reference, Anders Hejlsberg and Scott Wiltamuth
ECMA C# and Common Language Infrastructure Standards

Leave a reply

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

required