ebook img

Microsoft Visual C♯.Net step by step PDF

663 Pages·2002·9.133 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Microsoft Visual C♯.Net step by step

cover next page > Cover title: Microsoft Visual C# .Net Step By StepStep By Step (Redmond, Wash.) author: Sharp, John. publisher: isbn10 | asin: 0735612897 print isbn13: 9780735612891 ebook isbn13: 9780585487199 language: subject publication date: lcc: ddc: subject: cover next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_i next page > Page i Step by Step Microsoft® MICROSOFT® VISUAL C# NET STEP BY STEP John Sharp Jon Jagger < previous page page_i next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_ii next page > Page ii PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2002 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Cataloging-in-Publication Data Jagger, Jon, 1966- Microsoft Visual C# .NET Step by Step / Jon Jagger, John Sharp. p. cm. Includes index. ISBN 0-7356-1289-7 1. C# (Computer program language) 2. Microsoft Visual C#. I. Sharp, John, 1964- II. Title. QA76.73.C153 J32 2002 005.13'3--dc21 2001058662 Printed and bound in the United States of America. 1 2 3 4 5 6 7 8 9 QWT 7 6 5 4 3 2 Distributed in Canada by Penguin Books Canada Limited. A CIP catalogue record for this book is available from the British Library. Microsoft Press books are available through booksellers and distributors worldwide. For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329. Visit our Web site at www.microsoft.com/mspress. Send comments to [email protected]. ActiveX, IntelliSense, JScript, Microsoft, Microsoft Press, Visual Basic, Visual C++, Visual C#, Visual Studio, Windows, and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Other product and company names mentioned herein may be the trademarks of their respective owners. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. Acquisitions Editor: Danielle Bird Project Editor: Karen Szall Body Part No. X08-04481 < previous page page_ii next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_iii next page > Page iii Contents Acknowledgments ix Introduction xi Minimum System Requirements xi Finding Your Best Starting Point in This Book xii Corrections, Comments, and Help xiv Visit the Microsoft Press Web Site xiv Installing and Using the Practice Files xv Conventions and Features in This Book xxi PART 1 Introducing Microsoft Visual C# and Visual Studio.Net 1 Chapter 1 Welcome to C# 3 Beginning Programming with the Visual Studio .NET Environment 3 Writing Your First Program 6 Using Namespaces 11 Creating Documentation Using XML and Comments 14 Creating a Windows Forms Application 19 Chapter 1 Quick Reference 28 Chapter 2 Working with Variables, Operators, and Expressions 29 Understanding Statements 29 Using Identifiers 30 Identifying Keywords 30 Using Variables 31 Working with Primitive Data Types 33 Setting Arithmetic Operators 38 Chapter 2 Quick Reference 43 Chapter 3 Writing Methods and Applying Scope 45 Declaring Methods 45 Calling Methods 49 Understanding Scope 51 Writing and Calling Methods 54 Chapter 3 Quick Reference 62 Chapter 4 Using Decision Statements 63 Declaring bool Variables 63 Using Boolean Operators 64 Executing if Statements 67 Chapter 4 Quick Reference 78 < previous page page_iii next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_iv next page > Page iv Chapter 5 Using Iteration Statements 79 Using Compound Assignment Operators 79 Incrementing and Decrementing Variables 81 Writing while Statements 81 Writing for Statements 83 Writing do Statements 85 Chapter 5 Quick Reference 98 Chapter 6 Managing Errors and Exceptions 99 Coping with Errors 100 Trying Code and Catching Exceptions 101 Using Multiple catch Handlers 102 Writing a General catch Handler 103 Using Checked and Unchecked Integer Arithmetic 107 Throwing Exceptions 112 Writing a finally block 118 Chapter 6 Quick Reference 121 PART 2 Understanding the C# Language 123 Chapter 7 Creating and Managing Classes and Objects 125 What Is Classification? 125 What Is Encapsulation? 126 Controlling Accessibility 127 Working with Constructors and the new Keyword 129 Understanding static Methods and Data 139 Chapter 7 Quick Reference 144 Chapter 8 Understanding Values and References 147 Copying int Variables and Classes 147 Using ref and out Parameters 152 What Are the Stack and the Heap? 155 What Is System.Object? 157 Boxing 159 Unboxing 160 Chapter 8 Quick Reference 163 Chapter 9 Creating Value Types with Enumerations and Structs 165 Working with Enumerations 165 Working with struct Types 170 Chapter 9 Quick Reference 182 Chapter 10 Using Arrays and Collections 183 What is an Array? 183 What Are Collection Classes? 192 Chapter 10 Quick Reference 204 Chapter 11 Understanding Parameter Arrays 205 Creating Overloaded Methods 205 Using Array Arguments 206 Chapter 11 Quick Reference 218 < previous page page_iv next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_v next page > Page v Chapter 12 Working with Inheritance 219 What Is Inheritance? 219 Understanding Core Syntax 220 Creating Interfaces 226 Working with Multiple Interfaces 239 Summarizing Keyword Combinations 242 Chapter 12 Quick Reference 243 Chapter 13 Using Garbage Collection and Resource Management 245 Garbage Collection 245 Resource Management 250 Chapter 13 Quick Reference 259 PART 3 Creating Components 261 Chapter 14 Implementing Properties to Access Attributes 263 Comparing Fields and Methods 263 What Are Properties? 265 Understanding the Property Restrictions 268 Using Static Properties 269 Declaring Interface Properties 271 Chapter 14 Quick Reference 277 Chapter 15 Using Indexers 279 What Is an Indexer? 279 Interface Indexers 286 Using Indexers in a Windows Application 287 Chapter 15 Quick Reference 291 Chapter 16 Delegates and Events 293 Using Delegate Declarations and Instances 293 Enabling Notifications with Events 302 Chapter 16 Quick Reference 309 Chapter 17 Operator Overloading 311 Working with Operators 311 Declaring Conversion Operators 321 Chapter 17 Quick Reference 326 PART 4 Working with Windows Applications 327 Chapter 18 Introducing Windows Forms 329 Creating Your Application 330 Adding Controls to the Form 338 Publishing Events in Windows Forms 345 Chapter 18 Quick Reference 350 Chapter 19 Working with Menus 351 Menu Guidelines and Style 351 Adding Menus and Processing Menu Events 352 Pop-Up Menus 360 Chapter 19 Quick Reference 364 < previous page page_v next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_vi next page > Page vi Chapter 20 Performing Validation 365 Validating Data 365 An Example—Customer Maintenance 366 Chapter 20 Quick Reference 377 Chapter 21 Using Complex Controls 379 The Explorer Interface 379 Splitter Windows, Docking Controls, and Panels 381 Controls for Navigating Data 385 Chapter 21 Quick Reference 403 Chapter 22 Using the MDI, Windows, and Dialog Boxes 405 What Is the Multiple Document Interface? 406 Creating Dialog Boxes 412 Using Common Dialog Controls 416 Chapter 22 Quick Reference 419 Chapter 23 Creating GUI Components 421 Working with User Controls 421 Specializing Controls Using Subclassing 431 Chapter 23 Quick Reference 438 PART 5 Managing Data 439 Chapter 24 Using a Database 441 Using ADO.NET Databases 441 Using the Northwind Traders Database 442 Chapter 24 Quick Reference 459 Chapter 25 Working with Data Binding and DataSets 461 Windows Forms Controls and Data Binding 462 Disconnected DataSets 469 Chapter 25 Quick Reference 478 Chapter 26 Handling XML 479 Why XML? 479 The Employee Timesheet System 483 Chapter 26 Quick Reference 497 PART 6 Building Web Applications 499 Chapter 27 Introducing ASP.NET 501 Understanding the Internet as an Infrastructure 502 Creating Web Applications with ASP.NET 505 Chapter 27 Quick Reference 522 Chapter 28 Understanding Validation Controls 523 Comparing Server and Client Validations 523 Chapter 28 Quick Reference 531 < previous page page_vi next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_vii next page > Page vii Chapter 29 Accessing Data with Web Forms 533 Using the Web Forms DataGrid Control 533 Managing Security 534 Querying Data 539 Editing Data 547 Chapter 29 Quick Reference 553 Chapter 30 Building ASP.NET Applications 555 Additional Features of the DataGrid Control 555 Navigating Between Forms 564 Chapter 30 Quick Reference 571 Chapter 31 Building an XML Web Service 573 What is an XML Web Service? 573 Building the ProductService Web Service 578 Chapter 31 Quick Reference 590 Chapter 32 Consuming a Web Service 591 Web Services, Clients, and Proxies 591 Chapter 32 Quick Reference 602 About the Authors 603 Index 605 < previous page page_vii next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_viii next page > Page viii This page intentionally left blank. < previous page page_viii next page > http://avaxhome.ws/blogs/ChrisRedfield < previous page page_ix next page > Page ix Acknowledgments This is the first book I have written, but hopefully not the last. In undertaking this project, I never realized how much hard work it would be or how many people would be involved. I am now enlightened! There are far too many to thank individually, but I would like to mention Karen Szall and Danielle Bird at Microsoft Press, and Joe Perez, Stephanie Edmundson, Elisabeth Knottingham, and Lonnon Foster, and thank them for their enduring patience with my endless typos, grammatical errors, and jargon. I would also like to thank Suzanne Carlino, my project manager at Content Master, who beat me up and made sure I stuck to the schedule, and Robert Burbidge, who stepped in at the last minute and spent many thankless hours reviewing my work – and we are still friends! Finally, I would like to acknowledge the support and help given to me by my family – to Diana, who had to put up with me creeping to bed at 2:00 in the morning on many occasions (at least some occurrences of which were related to my book-writing activities), to James, who kept asking ‘‘Is Daddy STILL on that computer?,” and to Francesca, who just wants to see her name in a book. And finally, finally, “Up the Gills!”. John Sharp I’d like to dedicate this book to the five most important people in my life: my mother for having such a strong but gentle influence on me; my wife, Natalie, for making my life infinitely richer; and our three children, Ellie, Penny, and Patrick, who teach me important new things every day. I’d also like to thank everyone who has helped me learn interesting things, particularly Douglas Adams, Christopher Alexander, Sean Corfield, Richard Gabriel, Kevlin Henney, John Holt, and David Pye. Finally, I’d like to pay tribute to the elegance of the two-seater sports cars made by Marlin Engineering, the hilarity of the films made by Monty Python, the grass roots programming support provided by ACCU (http://www.accu.org), and the quality of life generated by the people of the village I live in. Jon Jagger < previous page page_ix next page > http://avaxhome.ws/blogs/ChrisRedfield

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.