Whether you need an approachable on-ramp to .NET or you want to enhance your skills, C# 3.0 Unleashed is a comprehensive, in-depth guide to the solutions you seek. Youll learn to do more with the new tools that are available, including Visual Studio 2008 and the .NET Framework Class Libraries. Throughout this book, youll get a practical look at what can be the most useful tools for any given task. Youll also learn common traps to avoid and learn insightful tips that will save you time and help you be more productive. C# 3.0 Unleashed contains complete coverage of the C# programming language. The author covers all the essential syntax, but keeps the focus on practical application. The chapters are arranged to take you step-by-step from the core of the C# language to elements of the .NET Framework, and further into advanced concepts on distributed n-tier Internet applications. Additionally, C# 3.0 Unleashed shows you how to debug, monitor, and scale enterprise applications, enabling you to use the C# programming language to ship the right code at the right time. Whats included in this book: A complete reference for C# syntax, object oriented programming, and component programming with C# Comprehensive data coverage through ADO.NET and LINQ An introduction to UI technologies, including Windows Forms, WPF, ASP.NET Ajax, and Silverlight Coverage of traditional ASMX and WCF Web Services Coverage of multiple .NET technologies, including networking, instrumentation, interop, and multi-threading In-depth discussion of platform concepts including CLR, Garbage Collection, Type System, Assemblies, and Code Access Security Guidance on design and architecture for a big-picture view and essential help in piecing together all youve learned Cover......Page 1 Contents......Page 6 Introduction......Page 30 Why This Book Is for You......Page 31 Organization and Goals......Page 32 Part 1 Learning C# Basics......Page 36 What Is .NET?......Page 38 The Common Language Runtime (CLR)......Page 40 The .NET Framework Class Library (FCL)......Page 43 C# and Other .NET Languages......Page 45 Summary......Page 46 Writing a Simple C# Program......Page 48 Creating a Visual Studio 2008 (VS2008) Project......Page 52 Commenting Code......Page 61 Identifiers and Keywords......Page 64 Convention and Style......Page 66 Variables and Types......Page 67 Definite Assignment......Page 73 Interacting with Programs......Page 74 Summary......Page 77 C# Operators......Page 78 Statements......Page 91 Labels......Page 92 Operator Precedence and Associativity......Page 93 Selection and Looping Statements......Page 94 Summary......Page 106 A Quick Introduction to Reference Types and Value Types......Page 108 The Unified Type System......Page 109 Reference Type and Value Type Memory Allocation......Page 114 Reference Type and Value Type Assignment......Page 117 More Differences Between Reference Types and Value Types......Page 121 C# and .NET Framework Types......Page 123 Nullable Types......Page 131 Summary......Page 132 The C# String Type......Page 134 The StringBuilder Class......Page 151 Regular Expressions......Page 153 Summary......Page 158 Arrays......Page 160 The System.Array Class......Page 166 Using Enum Types......Page 168 The System.Enum struct......Page 171 Summary......Page 174 Stepping Through Code......Page 176 Summary......Page 188 Part 2 Object-Oriented Programming with C#......Page 190 Object Members......Page 192 Instance and Static Members......Page 193 Fields......Page 194 Methods......Page 195 Properties......Page 196 Indexers......Page 198 Reviewing Where Partial Types Fit In......Page 199 Static Classes......Page 200 The System.Object Class......Page 201 Summary......Page 204 9 Designing Object-Oriented Programs......Page 206 Inheritance......Page 207 Encapsulating Object Internals......Page 213 Polymorphism......Page 219 Summary......Page 229 10 Coding Methods and Custom Operators......Page 230 Methods......Page 231 Overloading Methods......Page 239 Overloading Operators......Page 242 Conversions and Conversion Operator Overloads......Page 247 Partial Methods......Page 256 Extension Methods......Page 257 Summary......Page 259 11 Error and Exception Handling......Page 260 Exception Handler Syntax: The Basic try/catch Block......Page 261 Ensuring Resource Cleanup with finally Blocks......Page 263 Handling Exceptions......Page 264 Designing Your Own Exceptions......Page 272 checked and unchecked Statements......Page 274 Summary......Page 277 12 Event-Based Programming with Delegates and Events......Page 278 Exposing Delegates......Page 279 Assigning Anonymous Methods......Page 285 Coding Events......Page 287 Summary......Page 300 13 Naming and Organizing Types with Namespaces......Page 302 Why Namespaces?......Page 303 Namespace Directives......Page 304 Creating Namespaces......Page 307 Namespace Members......Page 310 Scope and Visibility......Page 311 Namespace Alias Qualifiers......Page 312 Extern Namespaces Alias......Page 313 Summary......Page 315 14 Implementing Abstract Classes and Interfaces......Page 316 Abstract Classes......Page 317 Abstract Class and Interface Differences......Page 319 Defining Interface Types......Page 320 Implicit Implementation......Page 322 Explicit Implementation......Page 333 Interface Mapping......Page 339 Interface Inheritance......Page 341 Summary......Page 344 Part 3 Applying Advanced C# Language Features......Page 346 15 Managing Object Lifetime......Page 348 Object Initialization......Page 349 Object Initializers......Page 355 Object Finalization......Page 356 Automatic Memory Management......Page 357 Proper Resource Cleanup......Page 360 Interacting with the Garbage Collector......Page 364 Summary......Page 366 16 Declaring Attributes and Examining Code with Reflection......Page 368 Using Attributes......Page 369 Using Attribute Parameters......Page 371 Attribute Targets......Page 373 Creating Your Own Attributes......Page 374 Using Reflection......Page 378 Reflecting on Attributes......Page 385 Summary......Page 392 17 Parameterizing Type with Generics and Writing Iterators......Page 394 Understanding the Benefits of Generics......Page 395 Building Generic Types......Page 401 Implementing Iterators......Page 417 Summary......Page 425 18 Using Lambda Expressions and Expression Trees......Page 426 Lambda Expressions......Page 427 Expression Trees......Page 433 Summary......Page 435 Part 4 Learning LINQ and .NET Data Access......Page 436 19 Accessing Data with LINQ......Page 438 LINQ to Objects......Page 439 Querying Relational Data with LINQ to SQL......Page 443 Standard Query Operators......Page 456 Summary......Page 468 ADO.NET Architecture......Page 470 Making Connections......Page 474 Viewing Data......Page 476 Manipulating Data......Page 479 Calling Stored Procedures......Page 481 Working with Disconnected Data......Page 482 LINQ to DataSet......Page 487 Summary......Page 488 21 Manipulating XML Data......Page 490 Writing XML......Page 491 Reading XML......Page 494 Working with the XML DOM......Page 495 Easier Manipulation with LINQ to XML......Page 497 Summary......Page 502 22 Creating Data Abstractions with the ADO.NET Entity Framework......Page 504 Starting the Entity Data Model in VS2008......Page 505 Querying Entities with Entity SQL......Page 509 Creating Custom Entities......Page 511 Coding with LINQ to Entities......Page 515 Summary......Page 518 23 Working with Data in the Cloud with ADO.NET Data Services......Page 520 Adding ADO.NET Data Services to Your Project......Page 521 Accessing ADO.NET Data Services via HTTP URIs......Page 522 Writing Code with the ADO.NET Data Services Client Library......Page 528 Summary......Page 533 Part 5 Building Desktop User Interfaces......Page 534 24 Taking Console Applications to the Limit......Page 536 Interacting with the User......Page 537 Handling Command-Line Input......Page 539 Adding Color and Positioning to Consoles......Page 540 Summary......Page 543 25 Writing Windows Forms Applications......Page 544 Windows Forms Fundamentals......Page 545 VS2008 Support for Windows Forms......Page 548 Using Windows Forms Controls......Page 557 MenuStrip, StatusStrip, and ToolStrip Controls......Page 560 Data Grids and Data Binding......Page 562 GDI+ Essentials......Page 565 Additional Windows and Dialogs......Page 568 Summary......Page 574 26 Creating Windows Presentation Foundation (WPF) Applications......Page 576 Just Enough XAML......Page 577 Managing Layout......Page 580 WPF Controls......Page 589 Event Handling......Page 602 Data Binding......Page 603 Using Styles......Page 607 Summary......Page 609 Part 6 Designing Web User Interfaces......Page 610 The Web Application Model......Page 612 Starting an ASP.NET Project with VS2008......Page 615 A Lap Around an ASP.NET Page......Page 617 Controls......Page 622 State Management......Page 625 Navigation......Page 632 Theming a Site......Page 638 Securing a Website......Page 641 Data Binding......Page 643 Summary......Page 646 What Is AJAX?......Page 648 Setting Up an ASP.NET AJAX Site......Page 649 The AJAX Page Life Cycle......Page 650 Loading Custom Script Libraries......Page 652 ASP.NET AJAX Controls......Page 654 Accessing Controls via JavaScript......Page 657 Calling Web Services with ASP.NET AJAX......Page 664 Summary......Page 669 What Makes Silverlight Tick?......Page 670 Starting a Silverlight Project in VS2008......Page 671 Handling Silverlight Events with C#......Page 677 Playing Media......Page 681 Animating UI Elements......Page 684 Summary......Page 686 Part 7 Communicating with .NET Technologies......Page 688 Implementing Sockets......Page 690 Working with HTTP......Page 698 Performing FTP File Transfers......Page 700 Sending SMTP Mail......Page 704 Summary......Page 705 31 Building Windows Service Applications......Page 708 Creating Windows Service Projects in VS2008......Page 709 Coding Windows Services......Page 712 Installing a Windows Service......Page 717 Building a Controller to Communicate with a Windows Service......Page 720 Summary......Page 722 Basic Remoting......Page 724 Channels......Page 735 Lifetime Management......Page 738 Summary......Page 741 Web Service Basics......Page 742 Using Web Services......Page 748 Summary......Page 752 34 Creating Web and Services with WCF......Page 754 Creating a WCF Application in VS2008......Page 755 Creating a Web Service Contract......Page 756 Implementing Web Service Logic......Page 761 Configuring a Web Service......Page 763 Consuming a Web Service......Page 766 Summary......Page 768 Part 8 Examining .NET Application Architecture and Design......Page 770 Visualizing Code......Page 772 Building an Object Model with the Class Designer......Page 778 Summary......Page 783 Overview of Design Patterns......Page 784 The Iterator Pattern......Page 785 Implementing the Proxy Pattern......Page 797 Implementing the Template Pattern......Page 801 Summary......Page 807 Potential Drag-and-Drop Problems......Page 808 Introducing N-Layer/N-Tier......Page 810 N-Layer Architecture Examples......Page 813 Summary......Page 824 Starting a Workflow Project......Page 826 Building a Sequential Workflow......Page 827 Building a State Workflow......Page 832 Summary......Page 842 Part 9 Surveying More of the .NET Framework Class Library......Page 844 39 Managing Processes and Threads......Page 846 .NET Process Support......Page 847 Multithreading Overview......Page 852 Thread Synchronization......Page 855 Summary......Page 858 Resource Files......Page 860 Multiple Locales......Page 872 Summary......Page 880 41 Performing Interop (P/Invoke and COM) and Writing Unsafe Code......Page 882 Unsafe Code......Page 883 Platform Invoke......Page 893 Communicating with COM from .NET......Page 895 Exposing a .NET Component as a COM Component......Page 898 Introduction to .NET Support for COM+ Services......Page 900 Summary......Page 905 42 Instrumenting Applications with System.Diagnostics Types......Page 908 Simple Debugging......Page 909 Conditional Debugging......Page 910 Runtime Tracing......Page 913 Making Assertions......Page 915 Accessing Built-In Performance Counters......Page 917 Implementing Timers......Page 925 Building a Customized Performance Counter......Page 926 Analyzing Performance with Sampling......Page 937 Summary......Page 946 Part 10 Deploying Code......Page 948 Inside Assemblies......Page 950 Assembly Features......Page 954 Configuration......Page 956 Summary......Page 959 Code-Based Security......Page 962 Role-Based Security......Page 971 Security Utilities......Page 973 Summary......Page 974 Running the VS2008 Setup Project Wizard......Page 976 Additional Setup Configuration......Page 979 Summary......Page 983 Deploying via ClickOnce......Page 984 Configuring ClickOnce......Page 986 Summary......Page 988 The Anatomy of a Web Application......Page 990 Web Server Setup......Page 991 Virtual Directory Setup......Page 992 Publishing a Web App from VS2008......Page 994 Summary......Page 995 Part 11 Appendixes......Page 996 Advanced......Page 998 Assemblies......Page 1000 Read This Book......Page 1002 .NET Framework Class Library Documentation......Page 1003 Summary......Page 1004 A......Page 1006 C......Page 1010 D......Page 1017 E......Page 1019 F......Page 1021 G......Page 1022 I......Page 1023 J–K......Page 1025 L......Page 1026 M......Page 1030 N......Page 1032 O......Page 1033 P......Page 1036 R......Page 1039 S......Page 1041 T......Page 1045 U......Page 1046 V......Page 1047 W......Page 1048 X–Z......Page 1051 Part 1 Learning C# Basics -- Part 2 Object-oriented Programming With C# -- Part 3 Applying Advanced C# Language Features -- Part 4 Learning Linq And .net Data Access -- Part 5 Building Desktop User Interfaces -- Part 6 Designing Web User Interfaces -- Part 7 Communicating With .net Technologies -- Part 8 Examining .net Application Architecture And Design -- Part 9 Surveying More Of The .net Framework Class Library -- Part 10 Deploying Code -- Part 11 Appendixes. Joe Mayo. Includes Index.