13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8 <strong>Language</strong> Overview8. <strong>Language</strong> OverviewThis clause is informative.<strong>C#</strong> (pronounced “C Sharp”) is a simple, modern, object oriented, and type-safe programming language. Itwill immediately be familiar to C and C++ programmers. <strong>C#</strong> combines the high productivity of RapidApplication Development (RAD) languages and the raw power of C++.The rest of this chapter describes the essential features of the language. While later chapters describe rulesand exceptions in a detail-oriented and sometimes mathematical manner, this chapter strives for clarity andbrevity at the expense of completeness. The intent is to provide the reader with an introduction to thelanguage that will facilitate the writing of early programs and the reading of later chapters.8.1 Getting startedThe canonical “hello, world” program can be written as follows:using System;class Hello{static void Main() {Console.WriteLine("hello, world");}}The source code for a <strong>C#</strong> program is typically stored in one or more text files with a file extension of .cs, asin hello.cs. Using a command-line compiler, such a program can be compiled with a command line likecsc hello.cswhich produces an application named hello.exe. The output produced by this application when it is runis:hello, worldClose examination of this program is illuminating:• The using System; directive references a namespace called System that is provided by the Common<strong>Language</strong> Infrastructure (CLI) class library. This namespace contains the Console class referred to inthe Main method. Namespaces provide a hierarchical means of organizing the elements of one or moreprograms. A using-directive enables unqualified use of the types that are members of the namespace.The “hello, world” program uses Console.WriteLine as shorthand forSystem.Console.WriteLine.• The Main method is a member of the class Hello. It has the static modifier, and so it is a method onthe class Hello rather than on instances of this class.• The entry point for an application—the method that is called to begin execution—is always a staticmethod named Main.• The “hello, world” output is produced using a class library. This standard does not include a classlibrary. Instead, it references the class library provided by CLI.For C and C++ developers, it is interesting to note a few things that do not appear in the “hello, world”program.• The program does not use a global method for Main. Methods and variables are not supported at theglobal level; such elements are always contained within type declarations (e.g., class and structdeclarations).15

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!