1. Trang chủ
  2. » Công Nghệ Thông Tin

Học lập trinh C từ cơ bản đến nâng cao

833 174 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 833
Dung lượng 9,74 MB

Nội dung

Đây là tài liệu bổ ích cho lập trình C.Bạn có thể làm chủ C một cách nhanh nhất.Cuốn sách này sẽ là những kiến thức từ cơ bản đến nâng cao giúp tăng khả năng tư duy cho mọi người.Cuốn sách viết bằng tiếng chuẩn.Kiến thức ngắn gọn thực tiễn.Qua các bài học có bài tập thực tế.

C# 7.0 All-in-One For Dummiesđ Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com Copyright â 2018 by John Wiley & Sons, Inc., Hoboken, New Jersey Media and software compilation copyright â 2018 by John Wiley & Sons, Inc All rights reserved 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 permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc and may not be used without written permission All other trademarks are the property of their respective owners John Wiley & Sons, 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 WITHOUT 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 ORGANIZATION 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 https://hub.wiley.com/community/support/dummies Wiley publishes in a variety of print and electronic formats and by print-ondemand Some material included with standard print versions of this book may not be included in e-books or in print-on-demand If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com For more information about Wiley products, visit www.wiley.com Library of Congress Control Number: 2017958295 ISBN: 978-111-9-42811-4; ISBN 978-111-9-42810-7 (ebk); ISBN ePDF 978111-9-42812-1 (ebk) C# 7.0 All-in-One For Dummies® To view this book's Cheat Sheet, simply go to www.dummies.com and search for “C# 7.0 All-in-One For Dummies Cheat Sheet” in the Search box Table of Contents Cover Introduction About This Book Foolish Assumptions Icons Used in This Book Beyond the Book Where to Go from Here Book 1: The 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 Declaring Numeric Constants Changing Types: The Cast Letting the C# Compiler Infer Data Types Chapter 3: Pulling Strings The Union Is Indivisible, and So Are Strings Performing Common Operations on a String Comparing Strings What If I Want to Switch Case? Looping through a String Searching Strings Getting Input from the Command Line Controlling Output Manually Formatting Your Strings Precisely StringBuilder: Manipulating Strings More Efficiently Chapter 4: Smooth Operators Performing Arithmetic Performing Logical Comparisons — Is That Logical? Matching Expression Types at TrackDownAMate.com Chapter 5: Getting into the Program Flow Branching Out with if and switch Here We Go Loop-the-Loop Looping a Specified Number of Times with for Nesting Loops Don’t goto Pieces Chapter 6: Lining Up Your Ducks with Collections The C# Array Processing Arrays by Using foreach Sorting Arrays of Data Using var for Arrays Loosening Up with C# Collections Understanding Collection Syntax Using Lists Using Dictionaries Array and Collection Initializers Using Sets On Not Using Old-Fashioned Collections Chapter 7: Stepping through Collections Iterating through a Directory of Files Iterating foreach Collections: Iterators Accessing Collections the Array Way: Indexers Looping Around the Iterator Block Chapter 8: Buying Generic Writing a New Prescription: Generics Classy Generics: Writing Your Own Revising Generics Chapter 9: Some Exceptional Exceptions Using an Exceptional Error-Reporting Mechanism Throwing Exceptions Yourself Knowing What Exceptions Are For Can I Get an Exceptional Example? Assigning Multiple catch Blocks Planning Your Exception-Handling Strategy Grabbing Your Last Chance to Catch an Exception Throwing Expressions Chapter 10: Creating Lists of Items with Enumerations Seeing Enumerations in the Real World Working with Enumerations Creating Enumerated Flags Defining Enumerated Switches Book 2: Object-Oriented C# Programming Chapter 1: Object-Oriented Programming — What’s It All About? Object-Oriented Concept #1: Abstraction Object-Oriented Concept #2: Classification Why Classify? Object-Oriented Concept #3: Usable Interfaces Object-Oriented Concept #4: Access Control How C# Supports Object-Oriented Concepts Chapter 2: Showing Some Class Defining a Class and an Object Accessing the Members of an Object An Object-Based Program Example Discriminating between Objects Can You Give Me References? Classes That Contain Classes Are the Happiest Classes in the World Generating Static in Class Members Defining const and readonly Data Members Chapter 3: We Have Our Methods Defining and Using a Method A Method Example for Your Files Having Arguments with Methods Returning Values after Christmas Returning Multiple Values Using Tuples Chapter 4: Let Me Say This about this Passing an Object to a Method Defining Methods Accessing the Current Object Using Local Functions Chapter 5: Holding a Class Responsible Restricting Access to Class Members Why You Should Worry about Access Control Defining Class Properties Getting Your Objects Off to a Good Start — Constructors The C#-Provided Constructor Replacing the Default Constructor Using Expression-Bodied Members Chapter 6: Inheritance: Is That All I Get? Class Inheritance Why You Need Inheritance Inheriting from a BankAccount Class (a More Complex Example) IS_A versus HAS_A — I’m So Confused_A When to IS_A and When to HAS_A Other Features That Support Inheritance The object Class Inheritance and the Constructor The Updated BankAccount Class Chapter 7: Poly-what-ism? Overloading an Inherited Method Polymorphism The Class Business Card: ToString() C# During Its Abstract Period Sealing a Class Chapter 8: Interfacing with the Interface Introducing CAN_BE_USED_AS Knowing What an Interface Is Using an Interface Using the C# Predefined Interface Types Looking at a Program That CAN_BE_USED_AS an Example Unifying Class Hierarchies Hiding Behind an Interface Inheriting an Interface Using Interfaces to Manage Change in Object-Oriented Programs Chapter 9: Delegating Those Important Events E.T., Phone Home — The Callback Problem Defining a Delegate Pass Me the Code, Please — Examples A More Real-World Example Shh! Keep It Quiet — Anonymous Methods Stuff Happens — C# Events Chapter 10: Can I Use Your Namespace in the Library? Dividing a Single Program into Multiple Source Files Dividing a Single Program into Multiple Assemblies Putting Your Classes into Class Libraries Going Beyond Public and Private: More Access Keywords Putting Classes into Namespaces Chapter 11: Improving Productivity with Named and Optional Parameters Exploring Optional Parameters Looking at Named Parameters Dealing with Overload Resolution Using Alternative Methods to Return Values Chapter 12: Interacting with Structures Comparing Structures to Classes Creating Structures Using Structures as Records Book 3: Designing for C# Chapter 1: Writing Secure Code Designing Secure Software Building Secure Windows Applications Building Secure Web Forms Applications Using System.Security Chapter 2: Accessing Data Getting to Know System.Data How the Data Classes Fit into the Framework Getting to Your Data Using the System.Data Namespace Chapter 3: Fishing the File Stream ), you add the pages in that section, such as Contact Us or Our Story The site map is only part of the picture, though You need some way to display it Next you need to create some means of displaying the information, which could be a master page or just a simple Web Form, as used in this chapter Create a Default.aspx page in the current project by using the technique you used in the “Digging up the request data” section, earlier in this chapter Add the following code between the opening and closing tag to create controls to display the site map, as shown here: When you run the example, you see the site map shown in Figure 4-4 Note how the TreeView reflects the hierarchical structure of the Web.sitemap The Home page acts as an anchor for the entire site Obviously, you can configure your site map as needed to meet your specific needs FIGURE 4-4: The site map should reflect the hierarchy of the content on your site Navigating a site with SiteMap With the web.sitemap file installed safely in the application, IIS now has a SiteMap collection that includes the XML file you made right there in memory If you need to figure out what other pages are related to the page the user is viewing, you can do that Follow these steps: Drag an empty ListBox control onto the Default.aspx page Go to Code View Add the following code to Page_Load() to loop through the items in the SiteMap collection and add items to the ListBox protected void Page_Load(object sender, EventArgs e) { // Reference the parent node to keep the object model happy string baseNode = SiteMap.CurrentNode.Title; // Check to make sure there are subpages if (SiteMap.CurrentNode.HasChildNodes) { foreach (SiteMapNode sitemapKids in SiteMap.CurrentNode.ChildNodes) { // Put the node name in the listbox ListBox1.Items.Add(new ListItem(sitemapKids.Title)); } } } If you get interested, put a debugger in the loop and check out that SiteMap object It’s a nice collection of the pages that have been referenced in the Web.sitemap file Though this technology won’t cure every navigational problem on every site, it is a nice, underused part of System.Web About the Author John Mueller is a freelance author and technical editor He has writing in his blood, having produced 104 books and more than 600 articles to date The topics range from networking to artificial intelligence and from database management to heads-down programming Some of his current works include a book about machine learning, a couple of Python books, and a book about MATLAB He has also written AWS For Admins For Dummies, which provides administrators with a great place to start with AWS, and AWS For Developers For Dummies, the counterpart for developers His technical editing skills have helped more than 70 authors refine the content of their manuscripts John has always been interested in development and has written about a wide variety of languages, including a highly successful C++ book Be sure to read John’s blog at http://blog.johnmuellerbooks.com/ You can reach John on the Internet at John@JohnMuellerBooks.com Dedication To Rebecca You’re in my heart forever! Acknowledgments Thanks to my wife, Rebecca Even though she is gone now, her spirit is in every book I write, in every word that appears on the page She believed in me when no one else would Russ Mullen deserves thanks for his technical edit of this book He greatly added to the accuracy and depth of the material you see here Russ worked exceptionally hard in helping with the research for this book by locating hardto-find URLs and also offering a lot of suggestions This was also an especially difficult book because of the changes involved in moving to C# 7.0 and Visual Studio 2017 There were a lot of really tough decisions that Russ helped me make Matt Wagner, my agent, deserves credit for helping me get the contract in the first place and taking care of all the details that most authors don’t really consider I always appreciate his assistance It’s good to know that someone wants to help Finally, I would like to thank Katie Mohr, Susan Christophersen, and the rest of the editorial and production staff at John Wiley & Sons, Inc for their unparalleled support of this writing effort Publisher’s Acknowledgments Executive Editor: Steve Hayes Project Manager and Copy Editor: Susan Christophersen Technical Editor: Russ Mullen Sr Editorial Assistant: Cherie Case Production Editor: Antony Sami Cover Image: © whiteMocca/Shutterstock Take Dummies with you everywhere you go! Go to our Website Like us on Facebook Follow us on Twitter Watch us on YouTube Join us on LinkedIn Pin us on Pinterest Circle us on google+ Subscribe to our newsletter Create your own Dummies book cover Shop Online WILEY END USER LICENSE AGREEMENT Go to www.wiley.com/go/eula to access Wiley’s ebook EULA ... ISBN: 978-111-9-42811-4; ISBN 978-111-9-42810-7 (ebk); ISBN ePDF 978111-9-42812-1 (ebk) C# 7.0 All-in-One For Dummies To view this book's Cheat Sheet, simply go to www .dummies. com and search for C# 7.0 All-in-One For Dummies Cheat Sheet” in the Search box... Of course, any language that does this much requires a bit of explanation, and C# 7.0 All-in-One For Dummies is your doorway to this new adventure in development So, why do you need C# 7.0 All-in-One For Dummies specifically? This book stresses learning the basics of the C# language before you do anything else... It provides you with some special notes about tasks that you can do with C# that not every other person knows To find the cheat sheet for this book, go to www .dummies. com and search for C# 7.0 All-in-One For Dummies Cheat Sheet It contains really neat information such as how to

Ngày đăng: 21/05/2018, 20:20

TỪ KHÓA LIÊN QUAN

w