Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Chapter 14: Unsafe code, exceptions, anonymous methods, iterators


Chapter 13<     > Chapter 15


Listings: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

Table of content:

Pointers and unsafe code
       Compilation options to allow unsafe code
        Declaring unsafe code in C#

Using pointers in C#
       .NET types that support pointers
       Declaring pointers
       Dereferencing and indirection operators
        The sizeof operator
       Pointer arithmetic
        Pointer casting
       Double pointers
        Pinned object
       Pointers and arrays
        Fixed arrays
        Allocating memory on the stack with the stackalloc keyword
       Strings and pointers

Handling errors with exceptions
       The underlying problem: How to properly handle most of the errors which can occur at runtime?
        Introduction to exception management in C#

Exception objects and defining custom exception classes
       The System.Exception class
       Defining custom exception classes
       Throwing exception from your code
       No checked exception in C#

Catch and finally blocks
       Notes on catch blocks (exception handlers)
       finally block
       Increasing exception semantics

Exceptions thrown from a constructor or from a finalizer
       Exception thrown from an instance constructor
       Exception thrown from a class constructor or while initializing a static field
       Exceptions thrown from a finalizer

Exception handling and the CLR
       Unmanaged exceptions

Exception handling and Visual Studio

Guidelines on exception management
       When should you consider throwing an exception?
       What to do in exception handlers?
       Where should you put exception handlers?
       Exceptions vs. returned error code
       Never under estimate bugs whose consequences are caught by exception handlers

Anonymous methods
        Introduction to C#2 anonymous methods
       Anonymous methods can accept arguments
       A syntax subtlety
       Anonymous methods and generics
       Use of anonymous methods in the real world

The C#2 compiler and anonymous methods
       The easy way
       Captured local variable
       Captured local variables and code complexity
       An anonymous method accesses to an argument of the outer method
       An anonymous method accessing a member of the outer class

Advanced uses of anonymous methods
       Definitions: closure and lexical environment
       Ramblings on closures
       Using closures instead of classes
       Delegates and closures
       Using anonymous methods to handle collections

C#1 iterators
       Enumerables, enumerators and the iterator design pattern
       An example
       Several enumerators for a single enumerable
       Drawbacks of C#1 iterators

C#2 iterators
        The keyword yield return
       Iterators and generics
       Several enumerators for a single enumerable
        The yield break keyword
       Syntactic constraints on yield return and yield break keywords
       A recursive iterator example

The C#2 compiler and iterators
       Enumerator classes are automatically built and used by the compiler
       Notes on generated classes

Advanced uses of C#2 iterators
       Definitions: coroutine and continuation
       Harness the power of continuations and coroutines with iterators
       The pipeline pattern
       Continuation vs. Threading
       A limitation of C#2 iterators



Copyright Patrick Smacchia 2006 2007