![]() CATEGORIES: BiologyChemistryConstructionCultureEcologyEconomyElectronicsFinanceGeographyHistoryInformaticsLawMathematicsMechanicsMedicineOtherPedagogyPhilosophyPhysicsPolicyPsychologySociologySportTourism |
Chapter 11 Events 249Designing a Type That Exposes an Event................................................ 250 Step #1: Define a type that will hold any additional information that should be sent to receivers of the event notification............... 251 Step #2: Define the event member................................................. 252 Step #3: Define a method responsible for raising the event to notify registered objects that the event has occurred.............. 253 Step #4: Define a method that translates the input into the desired event......................................................................... 256 How the Compiler Implements an Event.................................................. 256 Designing a Type That Listens for an Event............................................. 258 Explicitly Implementing an Event............................................................... 260 Chapter 12 Generics 265 Generics in the Framework Class Library................................................ 270 Generics Infrastructure................................................................................. 271 Open and Closed Types.................................................................... 272 Generic Types and Inheritance........................................................ 274 Generic Type Identity......................................................................... 275 Code Explosion................................................................................... 277 Generic Interfaces......................................................................................... 277 Generic Delegates........................................................................................ 278 Delegate and Interface Contra-variant and Covariant Generic Type Arguments....................................................................... 279 Generic Methods........................................................................................... 281 Generic Methods and Type Inference............................................ 283 Generics and Other Members..................................................................... 284 Verifiability and Constraints........................................................................ 284 Primary Constraints............................................................................ 287 Secondary Constraints...................................................................... 288 Constructor Constraints..................................................................... 289 Other Verifiability Issues.................................................................... 290 Contents xi
Chapter 13 Interfaces 295 Class and Interface Inheritance.................................................................. 296 Defining an Interface.................................................................................... 296 Inheriting an Interface................................................................................... 298 More About Calling Interface Methods...................................................... 300 Implicit and Explicit Interface Method Implementations (What’s Happening Behind the Scenes).............................................. 301 Generic Interfaces......................................................................................... 303 Generics and Interface Constraints........................................................... 305 Implementing Multiple Interfaces That Have the Same Method Name and Signature................................................................ 307 Improving Compile-Time Type Safety with Explicit Interface Method Implementations........................................................................ 308 Be Careful with Explicit Interface Method Implementations................. 310 Design: Base Class or Interface?............................................................... 312
Chapter 14 Chars, Strings, and Working with Text 317 Characters...................................................................................................... 317 The System.String Type.......................................................................... 320 Constructing Strings........................................................................... 320 Strings Are Immutable....................................................................... 323 Comparing Strings............................................................................. 323 String Interning.................................................................................... 329 String Pooling...................................................................................... 332 Examining a String’s Characters and Text Elements................... 333 Other String Operations..................................................................... 335 Constructing a String Efficiently................................................................. 336 Constructing a StringBuilder Object......................................... 336 StringBuilder Members............................................................... 337 Xii Contents
Obtaining a String Representation of an Object: ToString................ 339 Specific Formats and Cultures......................................................... 340 Formatting Multiple Objects into a Single String............................. 344 Providing Your Own Custom Formatter......................................... 345 Parsing a String to Obtain an Object: Parse............................................ 348 Encodings: Converting Between Characters and Bytes........................ 350 Encoding and Decoding Streams of Characters and Bytes......... 355 Base-64 String Encoding and Decoding........................................ 356 Secure Strings................................................................................................ 357 Date: 2016-03-03; view: 727
|