Chapter 4 Type Fundamentals 91All Types Are Derived from System.Object............................................ 91
Casting Between Types.................................................................................. 93
Casting with the C# is and as Operators........................................ 95
Namespaces and Assemblies...................................................................... 97
How Things Relate at Run Time................................................................. 101
Chapter 5 Primitive, Reference, and Value Types 111
Programming Language Primitive Types................................................ 111
Checked and Unchecked Primitive Type Operations.................. 115
Reference Types and Value Types............................................................ 118
Boxing and Unboxing Value Types........................................................... 124
Changing Fields in a Boxed Value Type by Using Interfaces
(and Why You Shouldn’t Do This).................................................... 136
Object Equality and Identity.............................................................. 139
Object Hash Codes....................................................................................... 142
The dynamic Primitive Type....................................................................... 144
Chapter 6 Type and Member Basics 151
The Different Kinds of Type Members...................................................... 151
Type Visibility................................................................................................. 154
Friend Assemblies.............................................................................. 154
Member Accessibility.................................................................................... 156
Static Classes................................................................................................. 158
Partial Classes, Structures, and Interfaces............................................... 159
Components, Polymorphism, and Versioning........................................ 160
How the CLR Calls Virtual Methods, Properties, and Events........ 162
Using Type Visibility and Member Accessibility Intelligently...... 166
Dealing with Virtual Methods When Versioning Types................ 169
Chapter 7 Constants and Fields 175
Constants........................................................................................................ 175
Fields............................................................................................................... 177
Chapter 8 Methods 181
Instance Constructors and Classes (Reference Types)......................... 181
Instance Constructors and Structures (Value Types).............................. 184
Type Constructors......................................................................................... 187
Contents ix
Operator Overload Methods...................................................................... 191
Operators and Programming Language Interoperability............ 193
Conversion Operator Methods.................................................................... 195
Extension Methods........................................................................................ 198
Rules and Guidelines......................................................................... 200
Extending Various Types with Extension Methods....................... 201
The Extension Attribute...................................................................... 203
Partial Methods.............................................................................................. 204
Rules and Guidelines......................................................................... 207
Chapter 9 Parameters 209
Optional and Named Parameters.............................................................. 209
Rules and Guidelines......................................................................... 210
The DefaultParameterValue and Optional Attributes......... 212
Implicitly Typed Local Variables................................................................. 212
Passing Parameters by Reference to a Method...................................... 214
Passing a Variable Number of Arguments to a Method........................ 220
Parameter and Return Type Guidelines.................................................... 223
Const-ness..................................................................................................... 224
Chapter 10 Properties 227
Parameterless Properties............................................................................ 227
Automatically Implemented Properties.......................................... 231
Defining Properties Intelligently....................................................... 232
Object and Collection Initializers..................................................... 235
Anonymous Types.............................................................................. 237
The System.Tuple Type.................................................................. 240
Parameterful Properties............................................................................... 242
The Performance of Calling Property Accessor Methods..................... 247
Property Accessor Accessibility.................................................................. 248
Generic Property Accessor Methods......................................................... 248
X Contents
Date: 2016-03-03; view: 783
|