๐”– Scriptorium
โœฆ   LIBER   โœฆ

๐Ÿ“

Essential Cโ™ฏ 4.0

โœ Scribed by Michaelis, Mark


Publisher
Addison-Wesley Professional
Year
2010
Tongue
English
Leaves
985
Series
Microsoft Windows Development Series
Category
Library

โฌ‡  Acquire This Volume

No coin nor oath required. For personal study only.

โœฆ Synopsis


Essential C# 4.0is a well-organized,"no-fluff" guide to all versions of C# for programmers at all levels of C# experience. This fully updated edition shows how to make the most of C# 4.0's new features and programming patterns to write code that is simple, yet powerful. This edition contains two new chapters on parallel programming, multi-threading, and concurrency, as well as extensive coverage of new C# 4.0 features: dynamic typing, variance, optional/named parameters, and many other new topics. Mark Michaelis covers the C# language in depth, illustrating key constructs with succinct, downloadable code examples. Graphical "mind maps" at the beginning of each chapter show what material is covered and how individual topics interrelate. Topics intended for beginners and advanced readers are clearly marked, and the book includes indexes of C# versions (2.0, 3.0, and 4.0), which make it easy for readers to reference topics specific to a given release of C#. Following an introduction to C#, readers learn about
Best practices for object-oriented programming in C#
C# primitive data types, value and reference types, implicitly typed variables, anonymous types, plus dynamic typing in C# 4.0
Methods and parameters-including extension methods, partial meth-ods, and C# 4.0's optional and named parameters
Generics, concurrent collections, and custom collections with iterators
Delegates, events, and lambda expressions
Collection interfaces and standard query operators
Query expressions and the tree expressions on which LINQ providers are based
Reflection, attributes, and dynamic programming
Parallel Query Processing with PLINQ
Multithreaded programming with the Task Parallel Library
Platform interoperability and unsafe code
The Common Language Infrastructure that underlies C# Whether you're just starting out, are an experienced developer moving to C#, or are a seasoned C# programmer seeking to master C# 4.0's most valuable enhancements, Essential C# 4.0 will help you write high-quality, highly effective code.

โœฆ Table of Contents


Cover......Page 1
Contents......Page 12
Contents of C# 4.0 Topics......Page 26
Figures......Page 28
Tables......Page 30
Foreword......Page 32
Preface......Page 36
Acknowledgments......Page 48
About the Author......Page 52
1 Introducing C#......Page 54
Hello, World......Page 55
Compiling and Running the Application......Page 56
C# Syntax Fundamentals......Page 57
Type Definition......Page 60
Main......Page 61
Statements and Statement Delimiters......Page 63
Whitespace......Page 64
Working with Variables......Page 65
Data Types......Page 66
Assigning a Variable......Page 67
Getting Input from the Console......Page 69
Writing Output to the Console......Page 71
Comments......Page 73
Managed Execution and the Common Language Infrastructure......Page 76
C# and .NET Versioning......Page 79
Common Intermediate Language and ILDASM......Page 80
Summary......Page 83
2 Data Types......Page 84
Integer Types......Page 85
Floating-Point Types (float, double)......Page 86
Decimal Type......Page 87
Literal Values......Page 88
Boolean Type (bool)......Page 93
Character Type (char)......Page 94
Strings......Page 96
null......Page 104
The void Nontype......Page 105
Value Types......Page 108
Reference Types......Page 109
Nullable Modifier......Page 110
Explicit Cast......Page 111
Type Conversion without Casting......Page 115
Arrays......Page 117
Declaring an Array......Page 118
Instantiating and Assigning Arrays......Page 119
Using an Array......Page 123
Strings as Arrays......Page 129
Common Errors......Page 131
Summary......Page 134
3 Operators and Control Flow......Page 136
Plus and Minus Unary Operators (+, -)......Page 137
Arithmetic Binary Operators (+, -, , /, %)......Page 138
Parenthesis Operator......Page 145
Assignment Operators (+=, -=,
=, /=, %=)......Page 146
Increment and Decrement Operators (++, --)......Page 147
Introducing Flow Control......Page 151
if Statement......Page 155
Nested if......Page 156
Code Blocks ({})......Page 158
Scope and Declaration Space......Page 160
Boolean Expressions......Page 162
Relational and Equality Operators......Page 163
Logical Boolean Operators......Page 164
Conditional Operator (?)......Page 166
Null Coalescing Operator (??)......Page 167
Bitwise Operators (<<, >>, |, &, ^, ~)......Page 168
Shift Operators (<<, >>, <<=, >>=)......Page 169
Bitwise Operators (&, |, ^)......Page 170
Bitwise Complement Operator (~)......Page 173
The while and do/while Loops......Page 174
The for Loop......Page 177
The foreach Loop......Page 180
The switch Statement......Page 183
The break Statement......Page 185
The continue Statement......Page 188
The goto Statement......Page 190
C# Preprocessor Directives......Page 191
Excluding and Including Code (#if, #elif, #else, #endif)......Page 193
Emitting Errors and Warnings (#error, #warning)......Page 194
Turning Off Warning Messages (#pragma)......Page 195
Specifying Line Numbers (#line)......Page 196
Hints for Visual Editors (#region, #endregion)......Page 197
Summary......Page 198
4 Methods and Parameters......Page 202
Calling a Method......Page 203
Namespace......Page 205
Type Name......Page 207
Method Return......Page 208
Statement versus Method Call......Page 209
Declaring a Method......Page 210
Method Return Declaration......Page 212
The using Directive......Page 214
Aliasing......Page 217
Returns and Parameters on Main()......Page 218
Value Parameters......Page 221
Reference Parameters (ref)......Page 223
Output Parameters (out)......Page 224
Parameter Arrays (params)......Page 226
Recursion......Page 229
Method Overloading......Page 232
Optional Parameters......Page 235
Basic Error Handling with Exceptions......Page 239
Trapping Errors......Page 240
Reporting Errors Using a throw Statement......Page 249
Summary......Page 252
5 Classes......Page 254
Declaring and Instantiating a Class......Page 258
Declaring an Instance Field......Page 262
Accessing an Instance Field......Page 263
Instance Methods......Page 264
Using the this Keyword......Page 266
Access Modifiers......Page 273
Properties......Page 275
Declaring a Property......Page 276
Automatically Implemented Properties......Page 278
Naming Conventions......Page 280
Using Properties with Validation......Page 281
Read-Only and Write-Only Properties......Page 283
Access Modifiers on Getters and Setters......Page 284
Properties as Virtual Fields......Page 285
Properties and Method Calls Not Allowed as ref or out Parameter Values......Page 287
Constructors......Page 289
Declaring a Constructor......Page 290
Object Initializers......Page 292
Overloading Constructors......Page 294
Constructor Chaining: Calling another Constructor Using this......Page 296
Static Members......Page 300
Static Fields......Page 301
Static Methods......Page 304
Static Constructors......Page 306
Static Properties......Page 307
Static Classes......Page 308
Extension Methods......Page 309
const......Page 311
readonly......Page 312
Nested Classes......Page 313
Partial Classes......Page 315
Defining a Partial Class......Page 316
Partial Methods......Page 317
Summary......Page 320
6 Inheritance......Page 322
Derivation......Page 323
Casting between Base and Derived Types......Page 325
private Access Modifier......Page 328
protected Access Modifier......Page 329
Single Inheritance......Page 331
Overriding the Base Class......Page 334
virtual Modifier......Page 335
new Modifier......Page 339
base Member......Page 344
Constructors......Page 345
Abstract Classes......Page 346
All Classes Derive from System.Object......Page 352
Verifying the Underlying Type with the is Operator......Page 354
Conversion Using the as Operator......Page 355
Summary......Page 356
7 Interfaces......Page 358
Introducing Interfaces......Page 359
Polymorphism through Interfaces......Page 360
Interface Implementation......Page 365
Explicit Member Implementation......Page 367
Implicit Member Implementation......Page 368
Explicit versus Implicit Interface Implementation......Page 369
Interface Inheritance......Page 371
Multiple Interface Inheritance......Page 374
Extension Methods on Interfaces......Page 375
Implementing Multiple Inheritance via Interfaces......Page 376
Versioning......Page 379
Interfaces Compared with Classes......Page 381
Summary......Page 382
8 Value Types......Page 384
Structs......Page 385
Initializing structs......Page 389
Inheritance and Interfaces with Value Types......Page 391
Boxing......Page 392
Enums......Page 399
Type Compatibility between Enums......Page 402
Converting between Enums and Strings......Page 403
Enums as Flags......Page 404
Summary......Page 409
Overriding object Members......Page 410
Overriding GetHashCode()......Page 411
Overriding Equals()......Page 414
Operator Overloading......Page 422
Comparison Operators (==, !=, <, >, <=, >=)......Page 423
Binary Operators (+, -, *, /, %, &, |, ^, <<, >>)......Page 424
Unary Operators (+, -, !, ~, ++, --, true, false)......Page 426
Conversion Operators......Page 428
Referencing Other Assemblies......Page 430
Changing the Assembly Target......Page 431
Encapsulation of Types......Page 432
Defining Namespaces......Page 435
Namespace Alias Qualifier......Page 437
XML Comments......Page 438
Associating XML Comments with Programming Constructs......Page 439
Generating an XML Documentation File......Page 441
Garbage Collection......Page 443
Weak References......Page 444
Finalizers......Page 446
Deterministic Finalization with the using Statement......Page 448
Garbage Collection and Finalization......Page 451
Lazy Initialization......Page 453
Summary......Page 456
Multiple Exception Types......Page 458
Catching Exceptions......Page 460
General Catch Block......Page 462
Guidelines for Exception Handling......Page 464
Defining Custom Exceptions......Page 467
Summary......Page 472
11 Generics......Page 474
C# without Generics......Page 475
Using a Generic Class......Page 480
Defining a Simple Generic Class......Page 482
Benefits of Generics......Page 483
Type Parameter Naming Guidelines......Page 484
Generic Interfaces and Structs......Page 485
Defining a Constructor and a Finalizer......Page 487
Specifying a Default Value......Page 488
Multiple Type Parameters......Page 489
Arity in Abundance......Page 490
Nested Generic Types......Page 491
Constraints......Page 492
Interface Constraints......Page 495
Base Class Constraints......Page 497
struct/class Constraints......Page 498
Constructor Constraints......Page 499
Constraint Inheritance......Page 500
Generic Methods......Page 506
Type Inferencing......Page 507
Specifying Constraints......Page 508
Covariance and Contravariance......Page 510
Enabling Covariance with the out Type Parameter Modifier in C# 4.0......Page 511
Enabling Contravariance with the in Type Parameter Modifier in C# 4.0......Page 513
Support for Parameter Covariance and Contravariance in Arrays......Page 515
Generic Internals......Page 516
Instantiating Generics Based on Value Types......Page 517
Instantiating Generics Based on Reference Types......Page 518
Summary......Page 520
12 Delegates and Lambda Expressions......Page 522
Defining the Scenario......Page 523
Delegate Data Types......Page 525
Delegate Internals......Page 526
Defining a Delegate Type......Page 527
Instantiating a Delegate......Page 528
Anonymous Methods......Page 533
System-Defined Delegates: Func<>......Page 536
Statement Lambdas......Page 539
Expression Lambdas......Page 542
Outer Variables......Page 548
Expression Trees......Page 551
Summary......Page 559
13 Events......Page 560
Defining Subscriber Methods......Page 561
Defining the Publisher......Page 563
Hooking Up the Publisher and Subscribers......Page 564
Invoking a Delegate......Page 565
Check for null......Page 566
Delegate Operators......Page 567
Sequential Invocation......Page 569
Error Handling......Page 572
Method Returns and Pass-by-Reference......Page 575
Why Events?......Page 576
Declaring an Event......Page 578
Coding Conventions......Page 579
Generics and Delegates......Page 581
Customizing the Event Implementation......Page 585
Summary......Page 586
14 Collection Interfaces with Standard Query Operators......Page 588
Anonymous Types and Implicitly Typed Local Variables......Page 589
Anonymous Types......Page 590
Implicitly Typed Local Variables (var)......Page 591
More about Anonymous Types and Implicit Local Variables......Page 593
Collection Initializers......Page 596
foreach with Arrays......Page 599
foreach with I Enumerable......Page 600
Standard Query Operators......Page 605
Filtering with Where()......Page 609
Projecting with Select()......Page 610
Counting Elements with Count()......Page 614
Deferred Execution......Page 615
Sorting with OrderBy() and ThenBy()......Page 619
Performing an Inner Join with Join()......Page 625
Grouping Results with GroupBy()......Page 628
Implementing a One-to-Many Relationship with GroupJoin()......Page 630
Calling SelectMany()......Page 633
More Standard Query Operators......Page 635
Summary......Page 639
15 LINQ with Query Expressions......Page 642
Introducing Query Expressions......Page 643
Projection......Page 645
Filtering......Page 651
Sorting......Page 652
The Let Clause......Page 653
Grouping......Page 655
Query Continuation with into......Page 658
Query Expressions as Method Invocations......Page 661
Summary......Page 662
16 Building Custom Collections......Page 664
More Collection Interfaces......Page 665
IComparable......Page 667
ICollection......Page 669
List Collections: List......Page 670
Dictionary Collections: Dictionary......Page 675
Sorted Collections: SortedDictionary and SortedList......Page 679
Stack Collections: Stack......Page 681
Linked Lists: LinkedList......Page 682
Providing an Index Operator......Page 683
Iterators......Page 687
Iterator Syntax......Page 689
Yielding Values from an Iterator......Page 690
Iterators and State......Page 692
More Iterator Examples......Page 694
Placing a yield return within a Loop......Page 696
Canceling Further Iteration: yield break......Page 698
Creating Multiple Iterators in a Single Class......Page 701
yield Statement Characteristics......Page 702
Summary......Page 703
17 Reflection, Attributes, and Dynamic Programming......Page 704
Reflection......Page 705
Accessing Metadata Using System.Type......Page 706
Member Invocation......Page 708
Reflection on Generic Types......Page 713
Attributes......Page 716
Custom Attributes......Page 719
Looking for Attributes......Page 720
Initializing an Attribute through a Constructor......Page 721
System.AttributeUsageAttribute......Page 726
Named Parameters......Page 727
Programming with Dynamic Objects......Page 741
Invoking Reflection Using dynamic......Page 742
dynamic Principles and Behaviors......Page 743
Why Dynamic Binding?......Page 747
Static Compilation versus Dynamic Programming......Page 748
Implementing a Custom Dynamic Object......Page 749
Summary......Page 752
18 Multithreading......Page 754
Running and Controlling a Separate Thread......Page 759
ContinueWith()......Page 764
Unhandled Exception Handling on Task......Page 768
Canceling a Task......Page 771
Long-Running Tasks......Page 775
Disposing a Task......Page 776
Executing Iterations in Parallel......Page 777
Parallel Exception Handling with System.AggregateException......Page 781
Canceling a Parallel Loop......Page 782
Running LINQ Queries in Parallel......Page 787
Canceling a PLINQ Query......Page 789
Asynchronous Operations with System.Threading.Thread......Page 791
Thread Management......Page 793
Thread Pooling......Page 795
Unhandled Exceptions on the AppDomain......Page 797
Summary......Page 799
19 Synchronization and More Multithreading Patterns......Page 802
Synchronization......Page 803
Synchronization Using Monitor......Page 807
Using the Lock Keyword......Page 810
Choosing a Lock Object......Page 811
Why to Avoid Locking on this, typeof(type), and string......Page 812
Declaring Fields as volatile......Page 813
Using the System.Threading.Interlocked Class......Page 814
Event Notification with Multiple Threads......Page 816
Synchronization Design Best Practices......Page 817
More Synchronization Types......Page 819
Thread Local Storage......Page 827
Timers......Page 831
Asynchronous Programming Model......Page 836
Calling the APM......Page 837
Calling the APM Using TPL......Page 844
Asynchronous Delegate Invocation......Page 850
Passing Data to and from an Alternate Thread......Page 852
Event-Based Asynchronous Pattern (EAP)......Page 854
Background Worker Pattern......Page 857
Establishing the Pattern......Page 860
Exception Handling......Page 861
Windows Forms......Page 862
Windows Presentation Foundation (WPF)......Page 864
Summary......Page 867
20 Platform Interoperability and Unsafe Code......Page 868
Platform Invoke......Page 869
Declaring External Functions......Page 870
Parameter Data Types......Page 871
Using ref Rather Than Pointers......Page 872
Using StructLayoutAttribute for Sequential Layout......Page 873
Error Handling......Page 874
Using SafeHandle......Page 876
Calling External Functions......Page 879
Simplifying API Calls with Wrappers......Page 881
Guidelines......Page 882
Unsafe Code......Page 883
Pointer Declaration......Page 885
Assigning a Pointer......Page 887
Dereferencing a Pointer......Page 890
Summary......Page 892
21 The Common Language Infrastructure......Page 896
Defining the Common Language Infrastructure (CLI)......Page 897
CLI Implementations......Page 898
C# Compilation to Machine Code......Page 900
Garbage Collection......Page 902
Garbage Collection on .NET......Page 903
Type Safety......Page 904
Platform Portability......Page 905
Performance......Page 906
Application Domains......Page 907
Assemblies, Manifests, and Modules......Page 908
Common Type System (CTS)......Page 911
Common Language Specification (CLS)......Page 912
Metadata......Page 913
Summary......Page 915
A: Downloading and Installing the C# Compiler and the CLI Platform......Page 918
B: Full Source Code Listings......Page 922
C: Concurrent Classes from System.Collections.Concurrent......Page 948
D: C# 2.0 Topics......Page 952
E: C# 3.0 Topics......Page 956
F: C# 4.0 Topics......Page 958
A......Page 960
C......Page 962
D......Page 966
E......Page 967
F......Page 968
H......Page 969
I......Page 970
J......Page 971
L......Page 972
M......Page 973
N......Page 974
O......Page 975
P......Page 976
R......Page 977
S......Page 978
T......Page 980
W......Page 982
Y......Page 983

โœฆ Subjects


Reference;Science;Computer Science;Technical


๐Ÿ“œ SIMILAR VOLUMES


Cโ™ฏ 4.0: the complete reference
โœ Schildt, Herbert ๐Ÿ“‚ Library ๐Ÿ“… 2010 ๐Ÿ› McGraw-Hill Education ๐ŸŒ English

Special Thanks; Preface; Part I: The C# Language; 1 The Creation of C#; C#'s Family Tree; How C# Relates to the .NET Framework; How the Common Language Runtime Works; Managed vs. Unmanaged Code; 2 An Overview of C#; Object-Oriented Programming; A First Simple Program; Handling Syntax Errors; A Small

Cโ™ฏ 4.0: the complete reference
โœ Schildt, Herbert ๐Ÿ“‚ Library ๐Ÿ“… 2010 ๐Ÿ› McGraw-Hill ๐ŸŒ English

Special Thanks; Preface; Part I: The C# Language; 1 The Creation of C#; C#'s Family Tree; How C# Relates to the .NET Framework; How the Common Language Runtime Works; Managed vs. Unmanaged Code; 2 An Overview of C#; Object-Oriented Programming; A First Simple Program; Handling Syntax Errors; A Small

Cโ™ฏ 3.0
โœ Schildt, Herbert ๐Ÿ“‚ Library ๐Ÿ“… 2009 ๐Ÿ› McGraw-Hill Professional Publishing ๐ŸŒ English

Special Thanks; Preface; Part I: The Cโ™ฏ Language; 1 The Creation of Cโ™ฏ; 2 An Overview of Cโ™ฏ; 3 Data Types, Literals, and Variables; 4 Operators; 5 Program Control Statements; 6 Introducing Classes and Objects; 7 Arrays and Strings; 8 A Closer Look at Methods and Classes; 9 Operator Overloading; 10 I

Essential C# 4.0
โœ Mark Michaelis ๐Ÿ“‚ Library ๐Ÿ“… 2010 ๐Ÿ› Addison-Wesley Professional ๐ŸŒ English

This is an excellent book about C# the language. Please read that again, as I can see a lot of people mistake what this book is - it is NOT a book about .Net (although it definitely is related to that) or about any specific frameworks that _use_ C#, such as WPF or ASP.Net or anything like that. It's

Essential C# 4.0
โœ Mark Michaelis ๐Ÿ“‚ Library ๐Ÿ“… 2010 ๐Ÿ› Addison-Wesley Professional ๐ŸŒ English

<BLOCKQUOTE>ย </BLOCKQUOTE> <P style="MARGIN: 0px"><B><I><B>Essential C# 4.0</B></I></B> is a well-organized,โ€œno-fluffโ€ guide to all versions of C# for programmers at all levels of C# experience. This fully updated edition shows how to make the most of C# 4.0โ€™s new features and programming patterns