Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C-sharp language specification.2004.pdf
Скачиваний:
14
Добавлен:
23.08.2013
Размер:
2.55 Mб
Скачать

Chapter 8 Language overview

18. Language overview

2This clause is informative.

3C# (pronounced “C Sharp”) is a simple, modern, object oriented, and type-safe programming language. It

4will immediately be familiar to C and C++ programmers. C# combines the high productivity of Rapid

5Application Development (RAD) languages and the raw power of C++.

6The rest of this clause describes the essential features of the language. While later clauses describe rules and

7exceptions in a detail-oriented and sometimes mathematical manner, this clause strives for clarity and

8brevity at the expense of completeness. The intent is to provide the reader with an introduction to the

9language that will facilitate the writing of early programs and the reading of later clauses.

108.1 Getting started

11The canonical “hello, world” program can be written as follows:

12using System;

13class Hello

14{

15

static void Main() {

16

Console.WriteLine("hello, world");

17}

18}

19The source code for a C# program is typically stored in one or more text files with a file extension of .cs, as

20in hello.cs. Using a command-line compiler, such a program can be compiled with a command line like

21csc hello.cs

22which produces an application named hello.exe. The output produced by this application when it is run

23is:

24hello, world

25Close examination of this program is illuminating:

26The using System; directive references a namespace called System that is provided by the Common

27Language Infrastructure (CLI) class library. This namespace contains the Console class referred to in

28the Main method. Namespaces provide a hierarchical means of organizing the elements of one or more

29programs. A using-directive enables unqualified use of the types that are members of the namespace.

30The “hello, world” program uses Console.WriteLine as shorthand for

31System.Console.WriteLine.

32The Main method is a member of the class Hello. It has the static modifier, and so it is a method on

33the class Hello rather than on instances of this class.

34The entry point for an application—the method that is called to begin execution—is always a static

35method named Main.

36The “hello, world” output is produced using a class library. This standard does not include a class

37library. Instead, it references the class library provided by CLI.

38For C and C++ developers, it is interesting to note a few things that do not appear in the “hello, world”

39program.

40The program does not use a global method for Main. Methods and variables are not supported at the

41global level; such elements are always contained within type declarations (e.g., class and struct

42declarations).

15

Соседние файлы в предмете Электротехника