Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Programming C# 5.0
Dedication
Preface
Who This Book Is For
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
1. Introducing C#
Why C#?
Why Not C#?
C#’s Defining Features
Managed Code and the CLR
Generality Trumps Specialization
Asynchronous Programming
Visual Studio
Anatomy of a Simple Program
Adding a Project to an Existing Solution
Referencing One Project from Another
Writing a Unit Test
Namespaces
Nested namespaces
Classes
Program Entry Point
Unit Tests
Summary
2. Basic Coding in C#
Local Variables
Scope
Variable name ambiguity
Local variable instances
Statements and Expressions
Statements
Expressions
Comments and Whitespace
Preprocessing Directives
Compilation Symbols
#error and #warning
#line
#pragma
#region and #endregion
Intrinsic Data Types
Numeric Types
Numeric conversions
Checked contexts
BigInteger
Booleans
Strings and Characters
Object
Operators
Flow Control
Boolean Decisions with if Statements
Multiple Choice with switch Statements
Loops: while and do
C-Style for Loops
Collection Iteration with foreach Loops
Summary
3. Types
Classes
Static Members
Static Classes
Reference Types
Structs
When to Write a Value Type
Members
Fields
Constructors
Methods
Passing arguments by reference
Optional arguments
Extension methods
Properties
Properties and mutable value types
Indexers
Operators
Events
Nested Types
Interfaces
Enums
Other Types
Anonymous Types
Partial Types and Methods
Summary
4. Generics
Generic Types
Constraints
Type Constraints
Reference Type Constraints
Value Type Constraints
Multiple Constraints
Zero-Like Values
Generic Methods
Type Inference
Inside Generics
Summary
5. Collections
Arrays
Array Initialization
Variable Argument Count with the params Keyword
Searching and Sorting
Multidimensional Arrays
Jagged arrays
Rectangular arrays
Copying and Resizing
List<T>
List and Sequence Interfaces
Implementing Lists and Sequences
Iterators
Collection<T>
ReadOnlyCollection<T>
Dictionaries
Sorted Dictionaries
Sets
Queues and Stacks
Linked Lists
Concurrent Collections
Tuples
Summary
6. Inheritance
Inheritance and Conversions
Interface Inheritance
Generics
Covariance and Contravariance
System.Object
The Ubiquitous Methods of object
Accessibility and Inheritance
Virtual Methods
Abstract Methods
Sealed Methods and Classes
Accessing Base Members
Inheritance and Construction
Special Base Types
Summary
7. Object Lifetime
Garbage Collection
Determining Reachability
Accidentally Defeating the Garbage Collector
Weak References
Reclaiming Memory
Garbage Collector Modes
Accidentally Defeating Compaction
Forcing Garbage Collections
Destructors and Finalization
Critical Finalizers
IDisposable
Optional Disposal
Boxing
Boxing Nullable<T>
Summary
8. Exceptions
Exception Sources
Exceptions from APIs
Exceptions from Your Code
Failures Detected by the Runtime
Handling Exceptions
Exception Objects
Multiple catch Blocks
Nested try Blocks
finally Blocks
Throwing Exceptions
Rethrowing Exceptions
Failing Fast
Exception Types
Custom Exceptions
Unhandled Exceptions
Debugging and Exceptions
Asynchronous Exceptions
Summary
9. Delegates, Lambdas, and Events
Delegate Types
Creating a Delegate
Multicast Delegates
Invoking a Delegate
Common Delegate Types
Type Compatibility
Behind the Syntax
Inline Methods
Captured Variables
Lambdas and Expression Trees
Events
Standard Event Delegate Pattern
Custom Add and Remove Methods
Events and the Garbage Collector
Events Versus Delegates
Delegates Versus Interfaces
Summary
10. LINQ
Query Expressions
How Query Expressions Expand
Supporting Query Expressions
Deferred Evaluation
LINQ, Generics, and IQueryable<T>
Standard LINQ Operators
Filtering
Select
Data shaping and anonymous types
Projection and mapping
SelectMany
Ordering
Containment Tests
Specific Items and Subranges
Aggregation
Set Operations
Whole-Sequence, Order-Preserving Operations
Grouping
Joins
Conversion
Sequence Generation
Other LINQ Implementations
Entity Framework
LINQ to SQL
WCF Data Services Client
Parallel LINQ (PLINQ)
LINQ to XML
Reactive Extensions
Summary
11. Reactive Extensions
Rx and .NET Versions
Fundamental Interfaces
IObserver<T>
IObservable<T>
Implementing cold sources
Implementing hot sources
Publishing and Subscribing with Delegates
Creating an Observable Source with Delegates
Subscribing to an Observable Source with Delegates
Sequence Builders
Empty
Never
Return
Throw
Range
Repeat
Generate
LINQ Queries
Grouping Operators
Join Operators
SelectMany Operator
Aggregation and Other Single-Value Operators
Concat Operator
Rx Query Operators
Merge
Windowing Operators
Demarcating windows with observables
The Scan Operator
The Amb Operator
DistinctUntilChanged
Schedulers
Specifying Schedulers
ObserveOn
SubscribeOn
Passing schedulers explicitly
Built-in Schedulers
Subjects
Subject<T>
BehaviorSubject<T>
ReplaySubject<T>
AsyncSubject<T>
Adaptation
IEnumerable<T>
.NET Events
Asynchronous APIs
Timed Operations
Interval
Timer
Timestamp
TimeInterval
Throttle
Sample
Timeout
Windowing Operators
Delay
DelaySubscription
Summary
12. Assemblies
Visual Studio and Assemblies
Anatomy of an Assembly
.NET Metadata
Resources
Multifile Assemblies
Other PE Features
Console versus GUI
Win32-style resources
Type Identity
Loading Assemblies
Explicit Loading
The Global Assembly Cache
Assembly Names
Strong Names
Version
Version numbers and assembly loading
Culture
Processor Architecture
Portable Class Libraries
Packaged Deployment
Windows 8 UI–Style Apps
ClickOnce and XBAP
Silverlight and Windows Phone Apps
Protection
Summary
13. Reflection
Reflection Types
Assembly
Module
MemberInfo
Type and TypeInfo
Generic types
MethodBase, ConstructorInfo, and MethodInfo
ParameterInfo
FieldInfo
PropertyInfo
EventInfo
Reflection Contexts
Summary
14. Dynamic Typing
The dynamic Type
dynamic and Interoperability
Silverlight and Scriptable Objects
Dynamic .NET Languages
Inside Dynamic
Restrictions on the dynamic Type
Custom Dynamic Objects
ExpandoObject
Limitations of dynamic
Summary
15. Attributes
Applying Attributes
Attribute Targets
Compiler-Handled Attributes
Names and versions
Description and related resources
Caller information attributes
CLR-Handled Attributes
InternalsVisibleToAttribute
Serialization
Security
JIT compilation
STAThread and MTAThread
Interop
Defining and Consuming Custom Attributes
Attribute Type
Retrieving Attributes
Reflection-only load
Summary
16. Files and Streams
The Stream Class
Position and Seeking
Flushing
Copying
Length
Disposal
Asynchronous Operation
Concrete Stream Types
Windows 8 and IRandomAccessStream
Text-Oriented Types
TextReader and TextWriter
Concrete Reader and Writer Types
StreamReader and StreamWriter
StringReader and StringWriter
Encoding
Code page encodings
Using encodings directly
Files and Directories
FileStream Class
File Class
Directory Class
Path Class
FileInfo, DirectoryInfo, and FileSystemInfo
Known Folders
Serialization
BinaryReader and BinaryWriter
CLR Serialization
Data Contract Serialization
Dictionaries
XmlSerializer
Summary
17. Multithreading
Threads
Threads, Variables, and Shared State
Thread-local storage
The Thread Class
The Thread Pool
Launching thread pool work with Task
Thread creation heuristics
I/O completion threads
Thread Affinity and SynchronizationContext
ExecutionContext
Synchronization
Monitors and the lock Keyword
How the lock keyword expands
Waiting and notification
Timeouts
SpinLock
Reader/Writer Locks
Event Objects
Barrier
CountdownEvent
Semaphores
Mutex
Interlocked
Lazy Initialization
Lazy<T>
LazyInitializer
Other Class Library Concurrency Support
Tasks
The Task and Task<T> Classes
Task creation options
Task status
Retrieving the result
Continuations
Continuation options
Schedulers
Error Handling
Custom Threadless Tasks
Parent/Child Relationships
Composite Tasks
Other Asynchronous Patterns
Cancellation
Parallelism
The Parallel Class
Parallel LINQ
TPL Dataflow
Summary
18. Asynchronous Language Features
Asynchronous Keywords: async and await
Execution and Synchronization Contexts
Multiple Operations and Loops
Returning a Task
Applying async to Nested Methods
The await Pattern
Error Handling
Validating Arguments
Singular and Multiple Exceptions
Concurrent Operations and Missed Exceptions
Summary
19. XAML
XAML-Based Frameworks
WPF
Silverlight
Windows Phone 7
Windows Runtime and Windows 8 UI–Style Apps
XAML Basics
XAML and XML Namespaces
Generated Classes and Codebehind
Child Elements
Property Elements
Event Handling
Threading
Layout
Properties
Alignment
Margin and Padding
Width and Height
Panels
Canvas
StackPanel
Grid
Windows Runtime specialized panels
WPF Panels
ScrollViewer
Layout Events
Controls
Content Controls
Slider and ScrollBar Controls
Progress Controls
List Controls
Windows Runtime list controls
WPF list controls
Control Templates
Template bindings
Visual state manager
UserControls
Text
Displaying Text
Blocks and flow
Editing Text
Data Binding
Data Templates
Graphics
Shapes
Bitmaps
ImageBrush
Media
Styles
Summary
20. ASP.NET
Razor
Expressions
Flow Control
Code Blocks
Explicitly Indicated Content
Page Classes and Objects
Using Other Components
Layout Pages
Start Pages
Web Forms
Server-Side Controls
Server-side HTML controls
Expressions
Code Blocks
Standard Page Objects
Page Classes and Objects
Using Other Components
Master Pages
MVC
Typical MVC Project Layout
Controllers
Models
Views
Writing Models
Writing Views
Writing Controllers
Handling Additional Input
Generating Action Links
Routing
Summary
21. Interoperability
Calling Native Code
Marshaling
String handling
Objects
Function pointers
Structures
Arrays
32-bit and 64-bit
Safe Handles
Security
Platform Invoke
Calling Convention
Text Handling
Entry Point Name
COM-Style Return Values
Win32 Error Handling
COM
RCW Lifetime
Metadata
Primary interop assemblies
Scripting
Windows Runtime
Metadata
Windows Runtime Types
Buffers
Unsafe Code
C++/CLI and the Component Extensions
Summary
Index
About the Author
Colophon
Copyright
← Prev
Back
Next →
← Prev
Back
Next →