c# 2010 AIO for dummies

867 4.3K 0
  c# 2010 AIO for dummies

Đ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

Tài liệu học lập trình C# cho sinh viên và mọi người.

Bill Sempf Chuck Sphar Stephen Randy Davis 8 IN 1 BOOKS BOOKS • Basics of C# Programming • Object Oriented C# • Designing for C# • A Tour of Visual Studio ® • Windows Programming • Web Programming • Service Oriented Development • C# 4.0 C# 2010 ALL-IN-ONE Making Everything Easier! ™ Visit the companion Web site at www.csharpfordummies. net to find the source code for all the projects in the book, updated for Visual Studio 2010 Open the book and find: • Steps for creating your first C# console application • How to take advantage of object- oriented programming • Techniques for writing secure code • Tips on how to use Visual Studio and create macros • Ways to implement Web services with SOAP • How to build Web applications and leverage the Framework • Where you can take your applications with dynamic programming Bill Sempf is a seasoned programmer and .NET evangelist specializing in .NET applications. Chuck Sphar is a programmer and former senior technical writer for the Visual C++ product group at Microsoft. Stephen Randy Davis is the bestselling author of several books, including C++ For Dummies. $39.99 US / $47.99 CN / £27.99 UK ISBN 978-0-470-56348-9 Web/Page Design Go to Dummies.com ® for videos, step-by-step examples, how-to articles, or to shop! Experience the fun and power as you learn to write your own C# applications What are you going to create with C#? Maybe your first Windows ® 7 application? Or how about digging into Web construction? With this comprehensive book, you’ll be able to decide where you want to go next. It takes you through everything from Visual Studio and WPF to Web and services development so you can start building your own applications. • Dig into C# — dive into object-oriented programming to create good class libraries • Make it secure — learn how to identify risks and then build Windows and Web applications with the right security • Jump into .NET — from coding for Windows Mobile to accessing XML files, you’ll uncover what you can do with the .NET framework • Develop with WPF — discover key WPF concepts as well as common application patterns used in the software industry today • Get Visual — find out how to use, optimize, and customize Visual Studio’s graphic user interface Basics of C# Programming Object Oriented C# Designing for C# A Tour of Visual Studio ® Windows Programming Web Programming Service Oriented Development C# 4.0 C# 2010 ALL-IN-ONE Sempf Sphar Davis spine=1.73” Start with FREE Cheat Sheets Cheat Sheets include • Checklists • Charts • Common Instructions • And Other Good Stuff! Get Smart at Dummies.com Dummies.com makes your life easier with 1,000s of answers on everything from removing wallpaper to using the latest version of Windows. Check out our • Videos • Illustrated Articles • Step-by-Step Instructions Plus, each month you can win valuable prizes by entering our Dummies.com sweepstakes. * Want a weekly dose of Dummies? Sign up for Newsletters on • Digital Photography • Microsoft Windows & Office • Personal Finance & Investing • Health & Wellness • Computing, iPods & Cell Phones • eBay • Internet • Food, Home & Garden Find out “HOW” at Dummies.com *Sweepstakes not currently available in all countries; visit Dummies.com for official rules. Get More and Do More at Dummies.com ® To access the Cheat Sheet created specifically for this book, go to www.dummies.com/cheatsheet/csharp2010aio spine=1.73” by Bill Sempf, Chuck Sphar, and Stephen Randy Davis C# 2010 ALL-IN-ONE FOR DUMmIES ‰ 01_563489-ffirs.indd i01_563489-ffirs.indd i 3/22/10 5:29 PM3/22/10 5:29 PM C# 2010 All-in-One For Dummies ® Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-5774 www.wiley.com Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permit- ted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its af liates in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITH- OUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZA- TION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www. wiley.com/techsupport. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: TK ISBN: 978-0-470-56348-9 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 01_563489-ffirs.indd ii01_563489-ffirs.indd ii 3/22/10 5:29 PM3/22/10 5:29 PM About the Authors Hi, my name is Bill Sempf, and I am a software architect. Although I used to hate the term architect, it’s clearly the only thing out there that de nes what I do. My breadth of experience includes business and technical analysis, software design, development, testing, server management and maintenance, and security. In my 17 years of professional experience, I have participated in the creation of well over 200 applications for large and small companies, managed the software infrastructure of two Internet service providers, coded complex software happily in every environment imaginable, and made mainframes talk to cellphones. In short, I make the technology products that people are using every day play nicely together. I started playing with computers in 1979 and haven’t looked back since. In 1985 I was helping my father (also named Bill) manage Apple IIe systems at the local library. Since then I have built applications for the likes of Bank One, Lucent Technologies, Nationwide Insurance, and Sears, Roebuck and Co. I am the author of Visual Basic 2008 For Dummies and Visual Basic 2005 For Dummies; a coauthor of Effective Visual Studio.NET, Professional ASP. NET Web Services, and Professional VB.NET; a frequent contributor to MSDN, Builder.com, Hardcore Web Services, Cloud Computing Journal, Inside Web Development Journal, and Intranet Journal; and have recently been an invited speaker for the ACM and IEEE, DevEssentials, the International XML Web Services Expo, and the Association of Information Technology Professionals. I am a graduate of The Ohio State University with a bachelor’s of science degree in business administration, a Microsoft Certi ed Professional, a Certi ed Internet Business Strategist, and a Certi ed Internet Webmaster. My company is Products Of Innovative New Technology (usually called POINT), and you can reach me at bill@pointWeb.net. Chuck Sphar escaped the Microsoft C++ documentation camps after six years of hard labor as a senior technical writer. You can reach Chuck for praise and minor nits at csharp@chucksphar.com. His C# material Web page (references throughout the book) is csharp102.info. Stephen R. Davis, who goes by the name Randy, lives with his wife and son near Dallas, Texas. 01_563489-ffirs.indd iii01_563489-ffirs.indd iii 3/22/10 5:29 PM3/22/10 5:29 PM 01_563489-ffirs.indd iv01_563489-ffirs.indd iv 3/22/10 5:29 PM3/22/10 5:29 PM Dedication This book goes to the active community of Microsoft developers that I get to work with every day. Thanks for your commitment to getting things done right, sharing what you know, and having a good time doing it. Also, for Gabrielle and Adam, who had to put up with another six months of Daddy hiding in the basement. —Sempf Acknowledgments A lot of people work to make a book of this size. Don’t think, just because the authors are listed on the front page, that they conceived every idea in the book. It takes a community. First, thanks to Chuck Sphar and Randy Davis for the fantastic source mate- rial that is the backbone of this book. I learned much just editing the  rst two minibooks for use in this All-in-One. Also, thanks to Katie Feltman and Chris Morris for their editorial expertise. A number of community members had a huge part in the creation of this book. Carey Payette and Phil Japikse built Book V (about WPF) basically from the goodness of their hearts, and I couldn’t have completed it without them — my WPF skills aren’t worth writing about. These two get the award for Biggest Contribution, and I thank them both. The developers at Information Control Corporation were also essential in for- mulating the initial scope of this book and then fact-checking the details. Steve Webb, Stephen Gif n, John Hannah, Larry Beall, Michael Birchmeyer, and Azher Muhammad all had a big part, especially in the information related speci cally to C# 4.0. Thanks to them and all the other ICC experts who gave me ideas and tips. Kevin Pilch-Bisson at Microsoft provided some C# clarity via Twitter through- out the scope of this book. Steve Andrews provided the structure for the T4 chapter in Book IV. Mads Torgerson reviewed the table of contents, and I thank him for the “It looks delicious” phrase, which I think was my most quoted phrase of the year. Lars Corneliussen provided a few choice pointers for the book, and Julie Lerman’s Entity Framework writing was the basis of my own additions to the ADO.NET chapter. As always, thanks to my wife, Gabrielle, for her support. Sometimes I just can’t believe how lucky I am. 01_563489-ffirs.indd v01_563489-ffirs.indd v 3/22/10 5:29 PM3/22/10 5:29 PM Publisher’s Acknowledgments We’re proud of this book; please send us your comments at http://dummies.custhelp.com. For other comments, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. Some of the people who helped bring this book to market include the following: Acquisitions, Editorial, and Media Development Senior Project Editor: Christopher Morris Acquisitions Editor: Katie Feltman Copy Editors: Debbye Butler, Heidi Unger, Becky Whitney Technical Editor: Mike Spivey Editorial Manager: Kevin Kirschner Media Development Project Manager: Laura Moss-Hollister Media Development Assistant Project Manager: Jenny Swisher Media Development Associate Producers: Josh Frank, Marilyn Hummel, Douglas Kuhn, Shawn Patrick Editorial Assistant: Amanda Graham Sr. Editorial Assistant: Cherie Case Cartoons: Rich Tennant (www.the5thwave.com) Composition Services Project Coordinator: Sheree Montgomery Layout and Graphics: Samantha K. Cherolis, Nikki Gately, Joyce Haughey Proofreader: Christine Sabooni Indexer: Broccoli Information Mgt. Publishing and Editorial for Technology Dummies Richard Swadley, Vice President and Executive Group Publisher Andy Cummings, Vice President and Publisher Mary Bednarek, Executive Acquisitions Director Mary C. Corder, Editorial Director Publishing for Consumer Dummies Diane Graves Steele, Vice President and Publisher Composition Services Debbie Stailey, Director of Composition Services 01_563489-ffirs.indd vi01_563489-ffirs.indd vi 3/22/10 5:29 PM3/22/10 5:29 PM Contents at a Glance Introduction 1 Book I: Basics of C# Programming 9 Chapter 1: Creating Your First C# Console Application 11 Chapter 2: Living with Variability — Declaring Value-Type Variables 25 Chapter 3: Pulling Strings 45 Chapter 4: Smooth Operators 73 Chapter 5: Getting Into the Program Flow 85 Chapter 6: Lining Up Your Ducks with Collections 109 Chapter 7: Stepping through Collections 135 Chapter 8: Buying Generic 169 Chapter 9: Some Exceptional Exceptions 187 Book II: Object-Oriented C# Programming 205 Chapter 1: Object-Oriented Programming: What’s It All About? 207 Chapter 2: Showing Some Class 215 Chapter 3: We Have Our Methods 227 Chapter 4: Let Me Say This about this 247 Chapter 5: Holding a Class Responsible 261 Chapter 6: Inheritance: Is That All I Get? 285 Chapter 7: Poly-what-ism? 307 Chapter 8: Interfacing with the Interface 333 Chapter 9: Delegating Those Important Events 357 Chapter 10: Can I Use Your Namespace in the Library? 377 Book III: Designing for C# 399 Chapter 1: Writing Secure Code 401 Chapter 2: Accessing Data 415 Chapter 3: Fishing the FileStream 435 Chapter 4: Accessing the Internet 455 Chapter 5: Creating Images 469 02_563489-ftoc.indd vii02_563489-ftoc.indd vii 3/19/10 8:01 PM3/19/10 8:01 PM Book IV: A Tour of Visual Studio 479 Chapter 1: Getting Started with Visual Studio 481 Chapter 2: Using the Interface 495 Chapter 3: Customizing Visual Studio 517 Chapter 4: Transforming Text Templates 533 Book V: Windows Development with WPF 543 Chapter 1: Introducing WPF 545 Chapter 2: Understanding the Basics of WPF 555 Chapter 3: Data Binding in WPF 579 Chapter 4: Practical WPF 601 Book VI: Web Development with ASP.NET 627 Chapter 1: Looking at How ASP.NET Works with C# 629 Chapter 2: Building Web Applications 641 Chapter 3: Controlling Your Development Experience 659 Chapter 4: Leveraging the .NET Framework 685 Chapter 5: Digging into Web Construction 703 Book VII: Service-Oriented Development 717 Chapter 1: Getting Acquainted with Web Services 719 Chapter 2: Building Web Services with ASMX 731 Chapter 3: Building Web Services with WCF 745 Chapter 4: Building Web Services with ReST 759 Book VIII: New Features in C# 4.0 767 Chapter 1: Programming Dynamically! 769 Chapter 2: Improving Productivity with Named and Optional Parameters 781 Chapter 3: Helping Out with Interop 789 Chapter 4: Revising Generics 795 Index 799 02_563489-ftoc.indd viii02_563489-ftoc.indd viii 3/19/10 8:01 PM3/19/10 8:01 PM [...]... 798 Index 799 Introduction C # 2010 All-in-One For Dummies represents a different way of looking at programming languages Rather than present the standard For Dummies format, which includes only 350 pages on quite a large subject, the book was expanded to include a broader scope and just a few pages were added So, although you find all the original C# For Dummies goodness in this book, you also... The C# Array 109 The argument for the array 110 The fixed-value array 110 The variable-length array 112 The Length property 114 Initializing an array 115 A Loop Made foreach Array 115 Sorting Arrays of Data 116 New Feature: Using var for Arrays 120 Loosening Up with C# Collections 121 xii C# 2010 All-in-One For. .. bulk of the original C# For Dummies book, and they cover the C# language, updated for version 4.0 Books III and IV cover technologies that are peripheral to C# Books V, VI, and VII cover the three main types of development you do in C# — Windows Presentation Foundation, Web development, and service-oriented programming We finish with the (thankfully short) Book VIII, about new C# 4.0 features If you’re... This minibook is an unconventional choice for Windows development For years in NET — since its inception — the choice for Windows developers was Windows Forms, the successor to the Ruby engine in Visual Basic 6 That’s just how you build Windows applications Even with the introduction of C# 4.0 and Visual Studio 2010, Windows Forms is likely the most common choice for development of Windows applications... companion Web site — check out www .dummies. com/go/csharp2010aiofd If you encounter a situation that you can’t figure out, check the Frequently Asked Questions (FAQ) list at the original Web site for the C# For Dummies book, at csharp102.info In addition, both sites include bonus chapters, a list of any mistakes that may have crept into the book, and other material on C# and programming that you may find... Obviously, your first step is to figure out the C# language — ideally, by using C# 2010 All-in-One For Dummies, of course You may want to give yourself a few months of practice in writing simple C# programs before taking the next step of discovering how to create graphical Windows applications Give yourself many months of Windows application experience before you branch out into writing programs intended... what you’ll find in each part of this book How This Book Is Organized 5 Book I: The Basics of C# Programming This minibook is the first of two that are based on the original C# For Dummies Book II: Object-Oriented C# Programming In Book II, we dig into the meat of the matter and discuss which tasks C# is good for This minibook covers how to create good class libraries and use the built-in libraries correctly... IV The original version of C# For Dummies (like all programming language books) focused on C# as a language, not all of the things you do with C# This version of the book — in the mondo-size All-in-One format — covers Windows development, Web development, service development, and NET Framework development, such as graphics and databases Our goal is to make a one-stop shop for development with Microsoft... samples for Book I and II, and many of the articles Csharpfordummies.net has a current blog, errata, and examples for the rest of the book This feature is designed to save you some typing time when your fingers start to cramp, but don’t abuse it: You gain a better understanding of C# when you enter the programs yourself and then use them as test beds for your explorations and experiments in C# Conventions... covers to see what the compiler has created from your lovely C# source code The NUnit testing tool, wildly popular among C# programmers, makes testing your code easy, whether it’s in Visual Studio or SharpDevelop 8 Where to Go from Here ✦ At csharpfordummies.net, you can find the source code for all projects in this book, updated for Visual Studio 2010 We give you a set of links to other resources and a

Ngày đăng: 24/01/2014, 18:04

Mục lục

  • C# 2010 All-In-One For Dummies®

    • About the Authors

    • Dedication

    • Acknowledgments

    • Table of Contents

    • Introduction

    • Book I: Basics of C# Programming

      • Chapter 1: Creating Your First C# Console Application

        • Getting a Handle on Computer Languages, C#, and .NET

        • Creating Your First Console Application

        • Making Your Console App Do Something

        • Reviewing Your Console Application

        • Introducing the Toolbox Trick

        • Chapter 2: Living with Variability — Declaring Value-Type Variables

          • Declaring a Variable

          • What’s an int?

          • Representing Fractions

          • Handling Floating-Point Variables

          • Using the Decimal Type: Is It an Integer or a Float?

          • Examining the bool Type: Is It Logical?

          • Checking Out Character Types

          • What’s a Value Type?

          • Comparing string and char

          • Calculating Leap Years: DateTime

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

Tài liệu liên quan