• home
  • forum
  • my
  • kt
  • download
  • C# Version 2.0 Specification

    Author: 2007-09-03 18:13:20 From:

    C#

    Version 2.0 Specification

    July 2003

    Alojamiento Web por Ferca Network


    Notice

    © 2003 Microsoft Corporation. All rights reserved.

    Microsoft, Windows, Visual Basic, Visual C#, and Visual C++ are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries/regions.

    Other product and company names mentioned herein may be the trademarks of their respective owners.


    Table of Contents

    19. Introduction to C# 2.0........................................................................................................................ 1

    19.1 Generics........................................................................................................................................... 1

    19.1.1 Why generics?............................................................................................................................ 1

    19.1.2 Creating and using generics.......................................................................................................... 2

    19.1.3 Generic type instantiations............................................................................................................ 3

    19.1.4 Constraints.................................................................................................................................. 3

    19.1.5 Generic methods......................................................................................................................... 5

    19.2 Anonymous methods.......................................................................................................................... 5

    19.2.1 Method group conversions........................................................................................................... 8

    19.3 Iterators............................................................................................................................................ 8

    19.4 Partial types.................................................................................................................................... 11

    20. Generics............................................................................................................................................ 13

    20.1 Generic class declarations................................................................................................................ 13

    20.1.1 Type parameters....................................................................................................................... 13

    20.1.2 The instance type...................................................................................................................... 14

    20.1.3 Base specification...................................................................................................................... 15

    20.1.4 Members of generic classes....................................................................................................... 15

    20.1.5 Static fields in generic classes..................................................................................................... 16

    20.1.6 Static constructors in generic classes.......................................................................................... 16

    20.1.7 Accessing protected members.................................................................................................... 17

    20.1.8 Overloading in generic classes.................................................................................................... 17

    20.1.9 Parameter array methods and type parameters............................................................................ 18

    20.1.10 Overriding and generic classes.................................................................................................. 19

    20.1.11 Operators in generic classes..................................................................................................... 19

    20.1.12 Nested types in generic classes................................................................................................. 20

    20.1.13 Application entry point.............................................................................................................. 21

    20.2 Generic struct declarations............................................................................................................... 21

    20.3 Generic interface declarations........................................................................................................... 21

    20.3.1 Uniqueness of implemented interfaces........................................................................................ 22

    20.3.2 Explicit interface member implementations.................................................................................. 22

    20.4 Generic delegate declarations........................................................................................................... 23

    20.5 Constructed types............................................................................................................................ 23

    20.5.1 Type arguments......................................................................................................................... 24

    20.5.2 Open and closed types............................................................................................................... 25

    20.5.3 Base classes and interfaces of a constructed type........................................................................ 25

    20.5.4 Members of a constructed type.................................................................................................. 25

    20.5.5 Accessibility of a constructed type.............................................................................................. 26

    20.5.6 Conversions.............................................................................................................................. 27

    20.5.7 The System.Nullable<T> type.................................................................................................... 27

    20.5.8 Using alias directives................................................................................................................. 27

    20.5.9 Attributes.................................................................................................................................. 28

    20.6 Generic methods.............................................................................................................................. 28

    20.6.1 Generic method signatures......................................................................................................... 29

    20.6.2 Virtual generic methods............................................................................................................. 30

    20.6.3 Calling generic methods............................................................................................................. 30

    20.6.4 Inference of type arguments....................................................................................................... 31

    20.6.5 Grammar ambiguities................................................................................................................. 32

    20.6.6 Using a generic method with a delegate...................................................................................... 32

    20.6.7 No generic properties, events, indexers, or operators.................................................................... 33

    20.7 Constraints...................................................................................................................................... 33

    20.7.1 Satisfying constraints................................................................................................................. 35

    20.7.2 Member lookup on type parameters............................................................................................ 36

    20.7.3 Type parameters and boxing....................................................................................................... 36

    20.7.4 Conversions involving type parameters........................................................................................ 37

    20.8 Expressions and Statements.............................................................................................................. 39

    20.8.1 Default value expression............................................................................................................ 39

    20.8.2 Object creation expressions........................................................................................................ 39

    20.8.3 The typeof operator................................................................................................................... 39

    20.8.4 Reference equality operators...................................................................................................... 40

    20.8.5 The is operator.......................................................................................................................... 40

    20.8.6 The as operator......................................................................................................................... 40

    20.8.7 Exception statements................................................................................................................. 41

    20.8.8 The lock statement.................................................................................................................... 41

    20.8.9 The using statement................................................................................................................... 41

    20.8.10 The foreach statement............................................................................................................. 41

    20.9 Revised lookup rules........................................................................................................................ 42

    20.9.1 Namespace and type names....................................................................................................... 42

    20.9.2 Member lookup......................................................................................................................... 43

    20.9.3 Simple names............................................................................................................................ 44

    20.9.4 Member access......................................................................................................................... 45

    20.9.5 Method invocations.................................................................................................................... 47

    20.9.6 Delegate creation expressions.................................................................................................... 48

    20.10 Right-shift grammar changes.......................................................................................................... 49

    21. Anonymous methods........................................................................................................................ 51

    21.1 Anonymous method expressions....................................................................................................... 51

    21.2 Anonymous method signatures.......................................................................................................... 51

    21.3 Anonymous method conversions....................................................................................................... 51

    21.3.1 Delegate creation expression...................................................................................................... 53

    21.4 Anonymous method blocks............................................................................................................... 53

    21.5 Outer variables................................................................................................................................ 53

    21.5.1 Captured outer variables............................................................................................................ 54

    21.5.2 Instantiation of local variables..................................................................................................... 54

    21.6 Anonymous method evaluation.......................................................................................................... 56

    21.7 Delegate instance equality................................................................................................................ 57

    21.8 Definite assignment.......................................................................................................................... 57

    21.9 Method group conversions................................................................................................................ 58

    21.10 Implementation example................................................................................................................. 59

    22. Iterators............................................................................................................................................ 63

    22.1 Iterator blocks................................................................................................................................. 63

    22.1.1 Enumerator interfaces................................................................................................................ 63

    22.1.2 Enumerable interfaces............................................................................................................... 63

    22.1.3 Yield type................................................................................................................................. 63

    22.1.4 This access............................................................................................................................... 64

    22.2 Enumerator objects.......................................................................................................................... 64

    22.2.1 The MoveNext method.............................................................................................................. 64

    22.2.2 The Current property................................................................................................................. 65

    22.2.3 The Dispose method.................................................................................................................. 66

    22.3 Enumerable objects.......................................................................................................................... 66

    22.3.1 The GetEnumerator method....................................................................................................... 66

    22.4 The yield statement.......................................................................................................................... 67

    22.4.1 Definite assignment................................................................................................................... 68

    22.5 Implementation example................................................................................................................... 68

    23. Partial Types..................................................................................................................................... 73

    23.1 Partial declarations........................................................................................................................... 73

    23.1.1 Attributes.................................................................................................................................. 73

    23.1.2 Modifiers.................................................................................................................................. 74

    23.1.3 Type parameters and constraints................................................................................................ 74

    23.1.4 Base class................................................................................................................................. 74

    23.1.5 Base interfaces......................................................................................................................... 75

    23.1.6 Members.................................................................................................................................. 75

    23.2 Name binding.................................................................................................................................. 76