Programming C# 5.0. Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo

Similar documents
Level: M.Ed. Credit Hour: 3 (2+1) Semester: Third Teaching Hour: 80(32+48)

Microsoft Visual C# Step by Step. John Sharp

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

CHAPTER 1: INTRODUCING C# 3

Microsoft. Microsoft Visual C# Step by Step. John Sharp

DOT NET Syllabus (6 Months)

C# 6.0 in a nutshell / Joseph Albahari & Ben Albahari. 6th ed. Beijin [etc.], cop Spis treści

DOT NET SYLLABUS FOR 6 MONTHS

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

C# Programming: From Problem Analysis to Program Design. Fourth Edition

Apex TG India Pvt. Ltd.

C# Programming in the.net Framework

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

Course Hours

Module 1. An Introduction to C# Module 2. Classes and Objects. Vasundhara Sector 14-A, Plot No , Near Vaishali Metro Station,Ghaziabad

CHAPTER 1: INTRODUCTION TO THE IDE 3

.NET-6Weeks Project Based Training

Advanced WCF 4.0 .NET. Web Services. Contents for.net Professionals. Learn new and stay updated. Design Patterns, OOPS Principles, WCF, WPF, MVC &LINQ

Variable Scope The Main() Function Struct Functions Overloading Functions Using Delegates Chapter 7: Debugging and Error Handling Debugging in Visual

Introduction to C++/CLI 3. What C++/CLI can do for you 6 The rationale behind the new syntax Hello World in C++/CLI 13

Programming in Visual Basic with Microsoft Visual Studio 2010

.Net. Course Content ASP.NET

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

Software Development & Education Center Complete.NET 4.5

DOT NET COURSE BROCHURE

C# Syllabus. MS.NET Framework Introduction

20483BC: Programming in C#

Dot Net Framework 4.0: Advanced Microsoft C#.NET Web Development

.NET Advance Package Syllabus

This module reviews the core syntax and features of the C# programming language. It also provides an introduction to the Visual Studio 2012 debugger.

Programming in C# (20483)

Beginning ASP.NET. 4.5 in C# Matthew MacDonald

Migrate Your Skills to Microsoft.NET Framework 2.0 and 3.0 using Visual Studio 2005 (C#)

SECURED PROGRAMMING IN.NET DETAILED TRAINING CONTENT INDUSTRIAL TRAINING PROGRAM ( )

Programming in C#

CHAPTER 1: VISUAL STUDIO

10262A VB: Developing Windows Applications with Microsoft Visual Studio 2010

ALPHAPRIMETECH 112 New South Road, Hicksville, NY 11801

10266 Programming in C Sharp with Microsoft Visual Studio 2010

10267A CS: Developing Web Applications Using Microsoft Visual Studio 2010

VS08 This One Goes to Going Parallel with PFX, PLINQ, TPL and Async Keywords

C# in Depth THIRD EDITION

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Introduction to Microsoft.NET Programming Using Microsoft Visual Studio 2008 (C#) Course Overview. Prerequisites. Audience.

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

The course introduces many of the techniques and technologies employed by modern desktop and enterprise applications, including:

Dot Net Online Training

Course Description. Audience. Module Title : 20483B: Programming in C# Duration : 5 days. Course Outline :: 20483B ::

C++/CLI in Action NISHANT SIVAKUMAR MANNING. Greenwich (74 w. long.)

DE Developing Windows Applications with Microsoft Visual Studio 2010

"Charting the Course to Your Success!" MOC B Programming in C# Course Summary

Developing Windows Applications with Microsoft Visual Studio 2010

OVERVIEW ENVIRONMENT PROGRAM STRUCTURE BASIC SYNTAX DATA TYPES TYPE CONVERSION

Diploma in Microsoft.NET

DNParallel - Version: 3. TPL Dataflow

Software Development & Education Center Complete.NET 4.5

Programming in C# for Experienced Programmers

Introducing C# and the.net Framework

Whom Is This Book For?... xxiv How Is This Book Organized?... xxiv Additional Resources... xxvi

Programming in C# with Microsoft Visual Studio 2010

Microsoft. Inside Microsoft. SharePoint Ted Pattison. Andrew Connell. Scot Hillier. David Mann

CodingFactory. Learn.NET MVC with WCF & Angular. This syllabus is cover all the basic to. Angular. Table of Contents

The C# Programming Language. Overview

RXTDF - Version: 1. Asynchronous Computing and Composing Asynchronous and Event- Based

Expert C++/CLI:.NET for Visual C++ Programmers

DEVELOPING WINDOWS APPLICATIONS WITH MICROSOFT VISUAL STUDIO 2010

C# in Depth SECOND EDITION JON SKEET. MANNING Greenwich (74 w. long.)

SERVICE-ORIENTED COMPUTING

Open Source Library Developer & IT Pro

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

"Charting the Course... MOC A Developing Data Access Solutions with Microsoft Visual Studio Course Summary

Bart De Smet C# 4.0 UNLEASHED

Mastering VB.NET using Visual Studio 2010 Course Length: 5 days Price: $2,500

Microsoft Programming in C#

.NET FRAMEWORK. Visual C#.Net

CETPA INFOTECH PVT. LTD.

"Charting the Course... MOC Programming in C# with Microsoft Visual Studio Course Summary

10265: Developing Data Access Solutions with Microsoft Visual Studio 2010 Duration: 5 Days Method: Instructor-Led

Programming in C# Course: Course Details ABOUT THIS COURSE AUDIENCE PROFILE. Síguenos en:

Microsoft.CerTkiller v by.SANDRA.65q

C# Programming Syllabus

Contents. 1 Introduction to Computers, the Internet. Before You Begin

--Microsoft-- --Windows Phone--

C#.NET TRAINING / /

Short Notes of CS201

Java Performance: The Definitive Guide

Developing Data Access Solutions with Microsoft Visual Studio 2010

DOT.NET MODULE 6: SILVERLIGHT

CS201 - Introduction to Programming Glossary By

Enterprise JavaBeans 3.1

Contents. Before You Begin. Object Technology: A Brief Review

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

Windows Presentation Foundation Programming Using C#

Advance Dotnet ( 2 Month )

Introduction to Programming Microsoft.NET Framework Applications with Microsoft Visual Studio 2005 (C#)

Microsoft Visual Studio 2010

Introduction to Microsoft.NET Framework Programming using VS 2005 (C#)

HCIM SUMMER WORKSHOP Introduction to C#

Microsoft.NET Programming (C#, ASP.NET,ADO.NET, VB.NET, Crystal Report, Sql Server) Goal: Make the learner proficient in the usage of MS Technologies

Transcription:

Programming C# 5.0 Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo

Preface xvii 1. Introducing C# 1 Why C#? 1 Why Not C#? 3 C#'s Defining Features 5 Managed Code and the CLR 7 Generality Trumps Specialization 9 Asynchronous Programming 10 Visual Studio ' 10 Anatomy of a Simple Program 13 Adding a Project to an Existing Solution 15 Referencing One Project from Another 15 Writing a Unit Test 17 Namespaces 20 Classes 24 Program Entry Point 25 Unit Tests 26 Summary 27 2. Basic Coding in C# 29 Local Variables 30 Scope 35 Statements and Expressions 39 Statements 39 Expressions. 40 Comments and Whitespace 46 Preprocessing Directives 48 Compilation Symbols 48 #error and #warning 49

#line 50 #pragma 50 #region and fendregion * 51 Intrinsic Data Types 51 Numeric Types 52 Booleans 61 Strings and Characters 62 Object 62 Operators 62 Flow Control 68 Boolean Decisions with if Statements 68 Multiple Choice with switch Statements 70 Loops: while and do 72 C-Style for Loops 73 Collection Iteration with foreach Loops 75 Summary 76 3. Types 77 Classes 77 Static Members 80 Static Classes 82 Reference Types 83 Structs 89 When to Write a Value Type 93 Members 98 Fields 98 Constructors 100 Methods 108 Properties 114 Indexers 117 Operators 119 Events 122 Nested Types 122 Interfaces 124 Enums 126 Other Types 129 Anonymous Types 129 Partial Types and Methods 130 Summary ' 131 4. Generics 133 Generic Types 134

Constraints 136 Type Constraints 137 Reference Type Constraints 139 Value Type Constraints 142 Multiple Constraints 142 Zero-Like Values 143 Generic Methods 144 Type Inference 145 Inside Generics 145 Summary 147 5. Collections 149 Arrays 149 Array Initialization 153 Variable Argument Count with the params Keyword 154 Searching and Sorting 155 Multidimensional Arrays 162 Copying and Resizing 166 List<T> 167 List and Sequence Interfaces 170. Implementing Lists and Sequences 174 Iterators 175 Collection<T> 179 ReadOnlyCollection<T> 180 Dictionaries 181 Sorted Dictionaries 184 Sets 185 Queues and Stacks 186 Linked Lists 187 Concurrent Collections 188 Tuples 189 Summary 190 6. Inheritance 191 Inheritance and Conversions 192 Interface Inheritance 194 Generics 195 Covariance and Contravariance 196 System.Object 202 The Ubiquitous Methods of object 202 Accessibility and Inheritance 203 Virtual Methods 204

Abstract Methods 206 Sealed Methods and Classes 213 Accessing Base Members 214 Inheritance and Construction 215 Special Base Types 220 Summary 221 7. Object Lifetime 223 Garbage Collection 224 Determining Reachability 225 Accidentally Defeating the Garbage Collector 227 Weak References 230 Reclaiming Memory 234 Garbage Collector Modes 240 Accidentally Defeating Compaction 242 Forcing Garbage Collections 245 Destructors and Finalization 246 Critical Finalizers 250 IDisposable 250 Optional Disposal 257 Boxing 257 Boxing Nullable<T> 262 Summary 263 8. Exceptions 265 Exception Sources 267 Exceptions from APIs 268 Exceptions from Your Code 270 Failures Detected by the Runtime 271 Handling Exceptions 272 Exception Objects 273 Multiple catch Blocks 274 Nested try Blocks 275 finally Blocks 277 Throwing Exceptions 278 Rethrowing Exceptions 279 Failing Fast 282 Exception Types 283 Custom Exceptions 285 Unhandled Exceptions 288 Debugging and Exceptions 290 Asynchronous Exceptions 292

t Summary 294 9. Delegates, Lambdas, and Events 295 Delegate Types 296 Creating a Delegate 297 Multicast Delegates 301 Invoking a Delegate 302 Common Delegate Types 305 Type Compatibility 306 Behind the Syntax 310 Inline Methods 313 Captured Variables 316 Lambdas and Expression Trees 323 Events 324 Standard Event Delegate Pattern 326 Custom Add and Remove Methods 327 Events and the Garbage Collector 330 Events Versus Delegates 332 Delegates Versus Interfaces 333 Summary 333 10. LINQ 335 Query Expressions 336 How Query Expressions Expand 339 Supporting Query Expressions 341 Deferred Evaluation 345 P LINQ, Generics, and IQueryable<T> 348 Standard LINQ Operators 350 Filtering 352 Select 354 SelectMany 357 Ordering 360 Containment Tests 362 Specific Items and Subranges 364 Aggregation 368 Set Operations 372 Whole-Sequence, Order-Preserving Operations 373 Grouping 374 Joins 379 Conversion 381 Sequence Generation 386 Other LINQ Implementations 386 k

Entity Framework 387 LINQ to SQL ^ 387 WCF Data Services Client " 388 Parallel LINQ (PLINQ) 388 LINQ to XML 388 Reactive Extensions 388 Summary 389 11. Reactive Extensions 391 Rx and.net Versions 393 Fundamental Interfaces 395 IObserver<T> 396 IObservable<T> 397 Publishing and Subscribing with Delegates 404 Creating an Observable Source with Delegates 404 Subscribing to an Observable Source with Delegates 407 Sequence Builders 409 Empty " 409 Never 409 Return 409 Throw 410 Range ' 410 Repeat 410 Generate 410 LINQ Queries 411 Grouping Operators 414 Join Operators 415 SelectMany Operator 420 Aggregation and Other Single-Value Operators 420 Concat Operator 422 Rx Query Operators 422 Merge 423 Windowing Operators 424 The Scan Operator 431 The Amb Operator 432 DistinctUntilChanged 433 Schedulers 434 Specifying Schedulers 434 Built-in Schedulers 437 Subjects 438 Subject<T> 438 BehaviorSubject<T> 440

ReplaySubject<T> 440 AsyncSubject<T> 441 Adaptation " 441 IEnumerable<T> 441.NET Events 443 Asynchronous APIs 445 Timed Operations 447 Interval 447 Timer 449 Timestamp 449 Timelnterval 450 Throttle 451 Sample 451 Timeout 451 Windowing Operators 451 Delay 452 DelaySubscription 453 Summary 453 12. Assemblies 455 Visual Studio and Assemblies 455 Anatomy of an-assembly 456.NET Metadata 457 Resources 457 Multifile Assemblies 457 Other PE Features 458 Type Identity 460 Loading Assemblies 462 Explicit Loading 465 The Global Assembly Cache 466 Assembly Names 468 Strong Names 468 Version 471 Culture 476 Processor Architecture 479 Portable Class Libraries 480 Packaged Deployment 482 Windows 8 Ul-Style Apps 482 ClickOnce and XBAP 483 Silverlight and Windows Phone Apps 484 Protection 485

Summary 486 13. Reflection \ 487 Reflection Types 488 Assembly 490_ Module 494 Memberlnfo 495 Type and Typelnfo 498 MethodBase, Constructorlnfo, and Methodlnfo 502 Parameterlnfo 504 Fieldlnfo 505 Propertylnfo 505 Eventlnfo 505 Reflection Contexts 506 Summary. 508 14. Dynamic Typing 509 The dynamic Type 511 dynamic and Interoperability 513 Silverlight and Scriptable Objects 516 Dynamic.NET Languages 517 Inside Dynamic 518 Restrictions on the dynamic Type 518 Custom Dynamic Objects 520 ExpandoObject 523 Limitations of dynamic 523 Summary 526 15. Attributes 527 Applying Attributes 527 Attribute Targets 530 Compiler-Handled Attributes 531 CLR-Handled Attributes 536 Defining and Consuming Custom Attributes 543 Attribute Type 544 Retrieving Attributes 546 Summary 548 16. Files and Streams 551 The Stream Class 552 Position and Seeking 554 Flushing 555

' Copying Length Disposal Asynchronous Operation Concrete Stream Types Windows 8 and IRandomAccessStream Text-Oriented Types TextReader and TextWriter Concrete Reader and Writer Types Encoding Files and Directories FileStream Class File Class Directory Class Path Class Filelnfo, Directorylnfo, and FileSystemlnfo Known Folders Serialization BinaryReader and BinaryWriter CLR Serialization Data Contract Serialization XmlSerializer Summary 556 556 558 559 559 ~~ 560 563 564 566 568 572 573 576 579 580 582 583 584 585 585 589 592 593 17. Multithreading Threads Threads, Variables, and Shared State The Thread Class The Thread Pool Thread Affinity and SynchronizationContext Synchronization Monitors and the lock Keyword SpinLock Reader/Writer Locks Event Objects Barrier CountdownEvent Semaphores Mutex Interlocked Lazy Initialization Other Class Library Concurrency Support 595 595 597 603 605 610 614 615 621 623 624 627 628 628 629 629 632 634 1 xiii

Tasks 635 ' The Task and Task<T> Classes 635 Continuations * 639 Schedulers 641 Error Handling 642 Custom Threadless Tasks 643 Parent/Child Relationships 645 Composite Tasks 645 Other Asynchronous Patterns 646 Cancellation 647 Parallelism 648 The Parallel Class 648 Parallel LINQ 649 TPL Dataflow 650 Summary 650 18. Asynchronous Language Features 651 Asynchronous Keywords: async and await 652 Execution and Synchronization Contexts 656 Multiple Operations and Loops 657 Returning a Task 660 Applying async to Nested Methods 662 The await Pattern 662 Error Handling 667 Validating Arguments 669 Singular and Multiple Exceptions 670 Concurrent Operations and Missed Exceptions 672 Summary 673 19. XAML 675 XAML-Based Frameworks 676 WPF 677 Silverlight 678 Windows Phone 7 680 Windows Runtime and Windows 8 Ul-Style Apps 680 XAML Basics 682 XAML and XML Namespaces 683 Generated Classes and Codebehind 684 Child Elements 686 Property Elements 687 Event Handling 688 Threading 689

Layout 690 Properties 691 Panels v 697 ScrollViewer 707 Layout Events 707 Controls. "^ 709 Content Controls 709 Slider and ScrollBar Controls 713 Progress Controls 713 List Controls 715 Control Templates 716 UserControls 720 Text 720 Displaying Text 721 Editing Text 723 Data Binding 724 Data Templates 728 Graphics 731 Shapes 731 Bitmaps 732 Media 733 Styles. 734 Summary 735 20. ASP.NET 737 Razor 738 Expressions 739 Flow Control 741 Code Blocks 742 Explicitly Indicated Content 743 Page Classes and Objects 744 Using Other Components 745 Layout Pages 746 Start Pages ' 747 Web Forms 748 Server-Side Controls 748 Expressions 754 Code Blocks 754 Standard Page Objects 755 Page Classes and Objects 756 Using Other Components 756 Master Pages 757 I xv

MVC 759 Typical MVC Project Layout 759 Writing Models * 766 Writing Views 768 Writing Controllers 770 Handling Additional Input *"** 772 Generating Action Links 775 Routing 775 Summary 780 21. Interoperability 781 Calling Native Code 781 Marshaling 782 32-bit and 64-bit 790 Safe Handles 791 Security 793 Platform Invoke 793 Calling Convention 794 Text Handling 795 Entry Point Name 795 COM-Style Return Values 796 Win32 Error. Handling 800 COM 800 RCW Lifetime 801 Metadata 803 Scripting 809 Windows Runtime 813 Metadata 813 Windows Runtime Types 813 Buffers 814 Unsafe Code 816 C++/CLI and the Component Extensions 818 Summary 818 Index 821 xvi I