introducing visual c 2010

1.3K 330 0
introducing visual c 2010

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info Introducing Visual C# 2010    Adam Freeman www.it-ebooks.info Introducing Visual C# 2010 Copyright © 2010 by Adam Freeman All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-3171-4 ISBN-13 (electronic): 978-1-4302-3172-1 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Ewan Buckingham Technical Reviewer: Damien Foggon Editorial Board: Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Anne Collett and Kelly Moritz Copy Editor: Kim Wimpsett and Mary Behr Compositor: Bytheway Publishing Services Indexer: BIM Indexing & Proofreading Services Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders- ny@springer-sbm.com, or visit www.springeronline.com. For information on translations, please e-mail rights@apress.com, or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at www.apress.com. www.it-ebooks.info iv Contents at a Glance  About the Author xxxii  About the Technical Reviewer xxxiii  Acknowledgments xxxiv PART 1    Getting Started 1  Chapter 1: Introduction 3  Chapter 2: Getting Ready 7  Chapter 3: Understanding C# and the .NET Framework 17 PART 2    The C# Language 31  Chapter 4: C# Fundamentals and Keyword Reference 33  Chapter 5: Numeric and Boolean Types 91  Chapter 6: Classes and Objects 131  Chapter 7: Fields 183  Chapter 8: Properties, Indexers, and Operators 203  Chapter 9: Methods 229  Chapter 10: Delegates, Events, and Anonymous Methods 305  Chapter 11: Namespaces 337  Chapter 12: Interfaces, Structs, and Enums 355  Chapter 13: Arrays 385  Chapter 14: Exceptions 419  Chapter 15: Generic and Anonymous Types 453  Chapter 16: Strings and Characters 481 www.it-ebooks.info  CONTENTS AT A GLANCE v  Chapter 17: Attributes 519  Chapter 18: Garbage Collection 539 PART 3    The .NET Class Library 549  Chapter 19: Collections 551  Chapter 20: Files, Streams, and IO 621  Chapter 21: Networking & WCF 675  Chapter 22: Time & Dates 711  Chapter 23: Serialization 735  Chapter 24: Serialization 735  Chapter 25: Asynchronous Methods and Parallel Loops 815  Chapter 26: Other Useful Features and Classes 833 PART 4    Data and Databases 861  Chapter 27: LINQ to Objects 863  Chapter 28: Parallel LINQ 915  Chapter 29: LINQ to XML 925  Chapter 30: LINQ to Entities 965  Chapter 31: LINQ to DataSet 1001 PART 5    User Interfaces 1031  Chapter 32: Windows Forms 1033  Chapter 33: Windows Presentation Foundation 1069  Chapter 34: ASP.NET 1099  Chapter 35: Silverlight 1125 PART 6    Advanced Topics 1159  Chapter 36: Windows Integration 1161  Chapter 37: Cryptography and Security 1185  Chapter 38: Testing and Debugging 1201  Index 1231 www.it-ebooks.info vi Contents  About the Authors xxxii  About the Technical Reviewers xxxiii  Acknowledgments xxxiv PART 1    Getting Started 1  Chapter 1: Introduction 3 Who Should Read This Book? 3 What Is Covered in This Book? 3 What Do You Need to Read This Book? 4 What Is the Structure of This Book? 4 What Is in Each Chapter? 4 Getting the Example Code 5 Finding More Information 6 The MSDN C# Programming Guide 6 Online Forums 6 Other Books 6 Summary 6  Chapter 2: Getting Ready 7 Installing the Software 7 Installing Visual Studio 2010 7 Installing SQL Server 2008 9 Installing the Silverlight Tools 10 Downloading the Sample Code and Data 10 www.it-ebooks.info  CONTENTS vii Creating Your First C# Project 10 Creating the Project 11 Editing the Code 13 Compiling and Running the Program 14 Features That I Use Before Explaining Them 14 The using statements 14 The namespace statement 15 The class statement 15 The Main method 15 The Code Comments 16 The Console.WriteLine and Console.ReadLine methods 16 Summary 16  Chapter 3: Understanding C# and the .NET Framework 17 C# and the .NET Framework at a Glance 17 Introducing C# 17 Introducing the .NET Framework 18 The Relationship between C# and the .NET Framework 19 Understanding Assemblies 20 The Key Features of C# and the .NET Framework 22 Understanding Object-Orientation 22 Understanding Type Safety 22 Understanding Automatic Memory Management 23 Understanding the Just-In-Time Compiler 23 Understanding Parallel Processing 23 Understanding Unmanaged/Native Code Support 24 Understanding the .NET Technology Spectrum 24 Understanding .NET Cross-Platform Support 29 Summary 30 www.it-ebooks.info  CONTENTS viii PART 2    The C# Language 31  Chapter 4: C# Fundamentals and Keyword Reference 33 Language Fundamentals 33 A Simple C# Program 33 C# Syntax 34 Types 41 Common Programming Tasks 46 Assigning Values 46 Making Comparisons 47 Performing Selections 49 Iterating Data Items 53 Keyword and Operator Reference 60 Type Keywords 61 Modifiers 69 Selection Keywords 75 Iterator Keywords 75 Jump Keywords 76 Exception Handling Keywords 77 Arithmetic Overflow Keywords 78 Synchronization Keywords 79 Parameter Keywords 79 Namespace Keywords 81 Literal Keywords 82 Object Keywords 83 LINQ Keywords 84 Other Keywords 84 Operators 87 Summary 89 www.it-ebooks.info  CONTENTS ix  Chapter 5: Numeric and Boolean Types 91 Numeric Types 92 Using Numeric Literals 93 Implicit and Explicit Numeric Type Conversions 98 Using Overflow Checking 101 Using Struct Members 103 Using Numeric Operators 109 Arithmetic Operators 109 Unary Operators 113 Relational Operators 116 Logical Operators 118 Assignment Operators 122 Working with Very Large Integer Values 126 The Boolean Type 127 Using Boolean Literals 127 Using Boolean Results 128 Using Struct Members 129 Summary 130  Chapter 6: Classes and Objects 131 Creating a Basic Class 132 Adding Features to a Class 133 Creating Objects from Classes 136 Using Objects 139 Class Inheritance 150 Understanding Inheritance 153 Understanding Encapsulation 159 Understanding Polymorphism 160 www.it-ebooks.info  CONTENTS x Casting Objects and Type Checking 165 Implicit vs. Explicit Casting. 165 Type Conversion Exceptions. 169 Avoiding Explicit Cast Exceptions. 170 Boxing and Unboxing. 173 Using Nested Classes 175 Using Class Modifiers 176 Creating Static Classes. 176 Creating Abstract Classes . 178 Creating Sealed Classes. 179 Creating Partial Classes. 179 Using Access Modifiers . 180 Summary 181  Chapter 7: Fields 183 Defining and Using Fields 184 Defining Fields. 184 Initializing Fields. 184 Reading and Updating Fields. 186 The Fourth Stage of the Life Cycle . 193 Applying Field Modifiers 193 Creating Static Fields . 194 Creating Read-Only Fields. 196 Applying Access Modifiers . 199 Hiding Base Class Fields . 199 Using the volatile Keyword. 201 Summary 201 www.it-ebooks.info [...]... TVal> Collection 593 Generic Sets 595 The ISet Interface 595 The HashSet Collection 597 The SortedSet Collection 599 Generic Queues and Stacks 602 The Queue Collection 602 The Stack Collection 604 Other Generic Collection Interfaces .606 The IComparer Interface ... Interface 555 The List Collection 556 The LinkedList Collection 575 The SortedList Collection 581 Generic Dictionaries .585 The IDictionary Interface 586 The KeyValuePair Structure 588 The Dictionary Collection 589 The SortedDictionary Collection... IEqualityComparer Interface 608 Treating Arrays as Collections .609 xviii www.it-ebooks.info  CONTENTS Creating Constrained Collections 613 Read-Only Lists 613 Other Read-Only Collections 614 Legacy Collections .617 Summary .619  Chapter 20: Files, Streams, and IO .621 Working with Files and Directories...  CONTENTS Getting Details of the Antecedent 797 Providing a Continuation Result 798 Creating Chains of Continuations 800 Creating Selective Continuations 801 Sharing Data between Tasks .803 Understanding a Critical Region 806 Creating a Critical Region 806 Avoiding Synchronization 808 Using Concurrent... Rules 1214 Performing Static Analysis 1215 Dealing with a Rule Violation 1216 xxx www.it-ebooks.info  CONTENTS Using Code Contracts 1221 Installing and Enabling Code Contract Support 1221 Writing Code Contracts 1222 Using the Static Checker 1226 Using the Runtime Checker 1229 Summary ... Method 530 Creating a Custom Attribute 532 Using a Custom Attribute 533 Defining Properties in a Custom Attribute 535 Controlling How a Custom Attribute Can Be Used 535 Controlling Attribute Inheritance 537 Summary .538  Chapter 18: Garbage Collection 539 Explicitly Running the Garbage Collector .540 Implementing... Operations 852 Using Conditional Compilation .853 Using Visual Studio to Define Symbols 855 Conditionally Compiling Methods 856 Checking Network Connectivity 857 Listening for Connectivity Changes 859 Summary .860 PART 4    Data and Databases 861  Chapter 27: LINQ to Objects 863 Performing a Simple... Meaningful Exceptions 441 Summary .451 xv www.it-ebooks.info  CONTENTS  Chapter 15: Generic and Anonymous Types .453 Using Generic Types 454 Defining a Generic Class 456 Creating Objects from Generic Classes 456 Implementing and Using Generic Class Members 457 Defining Multiple Parameter Types 460 Casting from... writer, and technical reviewer in cutting-edge technologies and has contributed to more than 50 books on NET, C# , Visual Basic and ASP.NET He is the co-founder of the Newcastle based user-group NEBytes (online at http://www.nebytes.net), is a multiple MCPD in NET 2.0 and NET 3.5 and can be found online at http://blog.littlepond.co.uk xxxiii www.it-ebooks.info www.it-ebooks.info www.it-ebooks.info CHAPTER... 461 Constraining Parameterized Types 462 Defining a Method-Specific Parameterized Type 465 Deriving from a Generic Base Class 467 Creating Generic Interfaces 471 Creating Generic Structs 472 Type Variance 472 Using the default Keyword 477 Using Anonymous Types 478 Summary .480  Chapter . Collection 597 The SortedSet<T> Collection 599 Generic Queues and Stacks 602 The Queue<T> Collection 602 The Stack<T> Collection 604 Other Generic Collection Interfaces. Using Struct Members 129 Summary 130  Chapter 6: Classes and Objects 131 Creating a Basic Class 132 Adding Features to a Class 133 Creating Objects from Classes 136 Using Objects 139 Class. www.it-ebooks.info Introducing Visual C# 2010    Adam Freeman www.it-ebooks.info Introducing Visual C# 2010 Copyright © 2010 by Adam Freeman All rights

Ngày đăng: 05/05/2014, 11:33

Từ khóa liên quan

Mục lục

  • Team rebOOk

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan