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

C# LANGUAGE SPECIFICATION

1The unchecked operator is convenient when writing constants of the signed integral types in hexadecimal

2notation. [Example:

3class Test

4{

5

public const int AllBits = unchecked((int)0xFFFFFFFF);

6public const int HighBit = unchecked((int)0x80000000);

7}

8Both of the hexadecimal constants above are of type uint. Because the constants are outside the int range,

9without the unchecked operator, the casts to int would produce compile-time errors. end example]

10[Note: The checked and unchecked operators and statements allow programmers to control certain

11aspects of some numeric calculations. However, the behavior of some numeric operators depends on their

12operands’ data types. For example, multiplying two decimals always results in an exception on overflow

13even within an explicitly unchecked construct. Similarly, multiplying two floats never results in an

14exception on overflow even within an explicitly checked construct. In addition, other operators are never

15affected by the mode of checking, whether default or explicit. As a service to programmers, it is

16recommended that the compiler issue a warning when there is an arithmetic expression within an explicitly

17checked or unchecked context (by operator or statement) that cannot possibly be affected by the specified

18mode of checking. Since such a warning is not required, the compiler has flexibility in determining the

19circumstances that merit the issuance of such warnings. end note]

2014.5.13 Default value expression

21A default value expression is used to obtain the default value (§12.2) of a type. Typically a default value

22expression is used for type parameters (§26.1.1), since it might not be known if the type parameter is a value

23type or a reference type. (No conversion exists from the null literal to a type parameter unless the type

24parameter is known to be a reference type (§26.7).)

25default-value-expression:

26default ( type )

27If the type in a default-value-expression evaluates at run-time to a reference type, the result is null

28converted to that type. If the type in a default-value-expression evaluates at run-time to a value type, the

29result is the value-type’s default value (§11.1.2).

30A default-value-expression is a constant expression (§14.15) if the type is a reference type or a type

31parameter that is known to be a reference type (§26.7). In addition, a default-value-expression is a constant

32expression if the type is one of the following value types: sbyte, byte, short, ushort, int, uint, long,

33ulong, char, float, double, decimal, or bool.

3414.5.14 Anonymous methods

35An anonymous-method-expression defines an anonymous method and evaluates to a value referencing the

36method:

37anonymous-method-expression:

38delegate anonymous-method-signatureopt block

39anonymous-method-signature:

40( anonymous-method-parameter-listopt )

41anonymous-method-parameter-list:

42

anonymous-method-parameter

43

anonymous-method-parameter-list , anonymous-method-parameter

44

anonymous-method-parameter:

45

parameter-modifieropt type identifier

46An anonymous-method-expression is classified as a value with no type, and with special conversion rules

47(§13.5). The value does not have a type but can be implicitly converted to a compatible delegate type.

180

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