c# how to program

1.6K 459 4
c# how to program

Đ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

Contents Contents viii Illustrations xix Preface xxxviii 1 Introduction to Computers, the Internet, the Web and C# 1 1.1 Introduction 2 1.2 What Is a Computer? 3 1.3 Computer Organization 3 1.4 Evolution of Operating Systems 4 1.5 Personal Computing, Distributed Computing and Client/Server Computing 5 1.6 Machine Languages, Assembly Languages and High-level Languages 6 1.7 C, C++, Visual Basic .NET and Java™ 7 1.8 C# 9 1.9 Other High-level Languages 10 1.10 Structured Programming 10 1.11 Key Software Trend: Object Technology 11 1.12 Hardware Trends 13 1.13 History of the Internet and World Wide Web 13 1.14 World Wide Web Consortium (W3C) 15 1.15 Extensible Markup Language (XML) 15 1.16 Introduction to Microsoft .NET 16 1.17 .NET Framework and the Common Language Runtime 18 1.18 Tour of the Book 20 1.19 Internet and World Wide Web Resources 29 Contents IX 2 Introduction to the Visual Studio .NET IDE 33 2.1 Introduction 34 2.2 Visual Studio .NET Integrated Development Environment (IDE) Overview 34 2.3 Menu Bar and Toolbar 37 2.4 Visual Studio .NET Windows 39 2.4.1 Solution Explorer 39 2.4.2 Toolbox 40 2.4.3 Properties Window 42 2.5 Using Help 42 2.6 Simple Program: Displaying Text and an Image 44 3 Introduction to C# Programming 59 3.1 Introduction 60 3.2 Simple Program: Printing a Line of Text 60 3.3 Another Simple Program: Adding Integers 71 3.4 Memory Concepts 75 3.5 Arithmetic 76 3.6 Decision Making: Equality and Relational Operators 80 4 Control Structures: Part 1 94 4.1 Introduction 95 4.2 Algorithms 95 4.3 Pseudocode 96 4.4 Control Structures 96 4.5 if Selection Structure 99 4.6 if/else Selection Structure 100 4.7 while Repetition Structure 105 4.8 Formulating Algorithms: Case Study 1 (Counter-Controlled Repetition) 106 4.9 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 2 (Sentinel-Controlled Repetition) 109 4.10 Formulating Algorithms with Top-Down, Stepwise Refinement: Case Study 3 (Nested Control Structures) 116 4.11 Assignment Operators 120 4.12 Increment and Decrement Operators 121 4.13 Introduction to Windows Application Programming 124 5 Control Structures: Part 2 139 5.1 Introduction 140 5.2 Essentials of Counter-Controlled Repetition 140 5.3 for Repetition Structure 142 5.4 Examples Using the for Structure 146 5.5 switch Multiple-Selection Structure 152 5.6 do/while Repetition Structure 156 5.7 Statements break and continue 158 5.8 Logical and Conditional Operators 160 5.9 Structured-Programming Summary 166 X Contents 6 Methods 178 6.1 Introduction 179 6.2 Program Modules in C# 179 6.3 Math Class Methods 181 6.4 Methods 181 6.5 Method Definitions 183 6.6 Argument Promotion 193 6.7 C# Namespaces 195 6.8 Value Types and Reference Types 196 6.9 Passing Arguments: Pass-by-Value vs. Pass-by-Reference 197 6.10 Random-Number Generation 200 6.11 Example: Game of Chance 207 6.12 Duration of Variables 212 6.13 Scope Rules 212 6.14 Recursion 215 6.15 Example Using Recursion: The Fibonacci Series 219 6.16 Recursion vs. Iteration 222 6.17 Method Overloading 223 7 Arrays 236 7.1 Introduction 237 7.2 Arrays 237 7.3 Declaring and Allocating Arrays 239 7.4 Examples Using Arrays 240 7.4.1 Allocating an Array and Initializing Its Elements 240 7.4.2 Totaling the Elements of an Array 242 7.4.3 Using Histograms to Display Array Data Graphically 243 7.4.4 Using the Elements of an Array as Counters 244 7.4.5 Using Arrays to Analyze Survey Results 247 7.5 Passing Arrays to Methods 250 7.6 Passing Arrays by Value and by Reference 253 7.7 Sorting Arrays 257 7.8 Searching Arrays: Linear Search and Binary Search 260 7.8.1 Searching an Array with Linear Search 260 7.8.2 Searching a Sorted Array with Binary Search 261 7.9 Multiple-Subscripted Arrays 265 7.10 foreach Repetition Structure 272 8 Object-Based Programming 280 8.1 Introduction 281 8.2 Implementing a Time Abstract Data Type with a Class 282 8.3 Class Scope 290 8.4 Controlling Access to Members 290 8.5 Initializing Class Objects: Constructors 292 8.6 Using Overloaded Constructors 293 8.7 Properties 297 Contents XI 8.8 Composition: Objects References as Instance Variables of Other Classes 306 8.9 Using the this Reference 309 8.10 Garbage Collection 311 8.11 static Class Members 312 8.12 const and readonly Members 317 8.13 Indexers 319 8.14 Data Abstraction and Information Hiding 326 8.15 Software Reusability 327 8.16 Namespaces and Assemblies 328 8.17 Class View and Object Browser 333 9 Object-Oriented Programming: Inheritance 342 9.1 Introduction 343 9.2 Base Classes and Derived Classes 344 9.3 protected and internal Members 347 9.4 Relationship between Base Classes and Derived Classes 347 9.5 Case Study: Three-Level Inheritance Hierarchy 368 9.6 Constructors and Destructors in Derived Classes 371 9.7 Software Engineering with Inheritance 377 10 Object-Oriented Programming: Polymorphism 382 10.1 Introduction 383 10.2 Derived-Class-Object to Base-Class-Object Conversion 383 10.3 Type Fields and switch Statements 390 10.4 Polymorphism Examples 391 10.5 Abstract Classes and Methods 392 10.6 Case Study: Inheriting Interface and Implementation 394 10.7 sealed Classes and Methods 402 10.8 Case Study: Payroll System Using Polymorphism 403 10.9 Case Study: Creating and Using Interfaces 413 10.10 Delegates 425 10.11 Operator Overloading 430 11 Exception Handling 438 11.1 Introduction 439 11.2 Exception Handling Overview 440 11.3 Example: DivideByZeroException 443 11.4 .NET Exception Hierarchy 448 11.5 finally Block 449 11.6 Exception Properties 457 11.7 Programmer-Defined Exception Classes 462 11.8 Handling Overflows with Operators checked and unchecked 466 12 Graphical User Interface Concepts: Part 1 474 12.1 Introduction 475 12.2 Windows Forms 476 XII Contents 12.3 Event-Handling Model 479 12.3.1 Basic Event Handling 480 12.4 Control Properties and Layout 484 12.5 Labels, TextBoxes and Buttons488 12.6 GroupBoxes and Panels495 12.7 CheckBoxes and RadioButtons498 12.8 PictureBoxes 507 12.9 Mouse Event Handling 509 12.10 Keyboard Event Handling 511 13 Graphical User Interfaces Concepts: Part 2 520 13.1 Introduction 521 13.2 Menus 521 13.3 LinkLabels530 13.4 ListBoxes and CheckedListBoxes 534 13.4.1 ListBoxes 537 13.4.2 CheckedListBoxes 539 13.5 ComboBoxes 542 13.6 TreeViews547 13.7 ListViews553 13.8 Tab Control 560 13.9 Multiple-Document-Interface (MDI) Windows 565 13.10 Visual Inheritance 574 13.11 User-Defined Controls 578 14 Multithreading 590 14.1 Introduction 591 14.2 Thread States: Life Cycle of a Thread 592 14.3 Thread Priorities and Thread Scheduling 594 14.4 Thread Synchronization and Class Monitor 599 14.5 Producer/Consumer Relationship without Thread Synchronization 601 14.6 Producer/Consumer Relationship with Thread Synchronization 607 14.7 Producer/Consumer Relationship: Circular Buffer 616 15 Strings, Characters and Regular Expressions 632 15.1 Introduction 633 15.2 Fundamentals of Characters and Strings 633 15.3 String Constructors 635 15.4 String Indexer, Length Property and CopyTo Method 636 15.5 Comparing Strings638 15.6 String Method GetHashCode 642 15.7 Locating Characters and Substrings in Strings643 15.8 Extracting Substrings from Strings646 15.9 Concatenating Strings647 15.10 Miscellaneous String Methods 648 Contents XIII 15.11 Class StringBuilder 650 15.12 StringBuilder Indexer, Length and Capacity Properties, and EnsureCapacity Method 652 15.13 StringBuilder Append and AppendFormat Methods 654 15.14 StringBuilder Insert, Remove and Replace Methods 658 15.15 Char Methods 661 15.16 Card Shuffling and Dealing Simulation 664 15.17 Regular Expressions and Class Regex 668 16 Graphics and Multimedia 684 16.1 Introduction 685 16.2 Graphics Contexts and Graphics Objects 687 16.3 Color Control 688 16.4 Font Control 696 16.5 Drawing Lines, Rectangles and Ovals 701 16.6 Drawing Arcs 704 16.7 Drawing Polygons and Polyli]nes 707 16.8 Advanced Graphics Capabilities 711 16.9 Introduction to Multimedia 717 16.10 Loading, Displaying and Scaling Images 718 16.11 Animating a Series of Images 720 16.12 Windows Media Player 733 16.13 Microsoft Agent 736 17 Files and Streams 757 6 17.1 Introduction 757 17.2 Data Hierarchy 757 17.3 Files and Streams 759 17.4 Classes File and Directory 761 17.5 Creating a Sequential-Access File 771 17.6 Reading Data from a Sequential-Access File 783 17.7 Random-Access Files 794 17.8 Creating a Random-Access File 798 17.9 Writing Data Randomly to a Random-Access File 802 17.10 Reading Data Sequentially from a Random-Access File 807 17.11 Case Study: A Transaction-Processing Program 812 18 Extensible Markup Language (XML) 838 18.1 Introduction 839 18.2 XML Documents 839 18.3 XML Namespaces 844 18.4 Document Object Model (DOM) 847 18.5 Document Type Definitions (DTDs), Schemas and Validation 865 18.5.1 Document Type Definitions 866 18.5.2 Microsoft XML Schemas 869 18.5.3 W3C XML Schema 872 XIV Contents 18.5.4 Schema Validation in C# 873 18.6 Extensible Stylesheet Language and XslTransform 877 18.7 Microsoft BizTalk™ 884 18.8 Internet and World Wide Web Resources 887 19 Database, SQL and ADO .NET 895 19.1 Introduction 896 19.2 Relational Database Model 897 19.3 Relational Database Overview: Books Database 898 19.4 Structured Query Language (SQL) 905 19.4.1 Basic SELECT Query 905 19.4.2 WHERE Clause 906 19.4.3 ORDER BY Clause 909 19.4.4 Merging Data from Multiple Tables: INNER JOIN 912 19.4.5 Joining Data from Tables Authors, AuthorISBN, Titles and Publishers 914 19.4.6 INSERT Statement 917 19.4.7 UPDATE Statement 918 19.4.8 DELETE Statement 919 19.5 ADO .NET Object Model 920 19.6 Programming with ADO .NET: Extracting Information from a DBMS 921 19.6.1 Connecting to and Querying an Access Data Source 921 19.6.2 Querying the Books Database 928 19.7 Programming with ADO.NET: Modifying a DBMS 930 19.8 Reading and Writing XML Files 938 20 ASP .NET, Web Forms and Web Controls 948 20.1 Introduction 949 20.2 Simple HTTP Transaction 950 20.3 System Architecture 952 20.4 Creating and Running a Simple Web Form Example 953 20.5 Web Controls 966 20.5.1 Text and Graphics Controls 967 20.5.2 AdRotator Control 971 20.5.3 Validation Controls 976 20.6 Session Tracking 987 20.6.1 Cookies 988 20.6.2 Session Tracking with HttpSessionState 997 20.7 Case Study: Online Guest Book 1006 20.8 Case Study: Connecting to a Database in ASP .NET 1013 20.9 Tracing 1027 20.10 Internet and World Wide Web Resources 1030 21 ASP .NET and Web Services 1039 21.1 Introduction 1040 Contents XV 21.2 Web Services 1041 21.3 Simple Object Access Protocol (SOAP) and Web Services 1044 21.4 Publishing and Consuming Web Services 1046 21.5 Session Tracking in Web Services 1062 21.6 Using Web Forms and Web Services 1075 21.7 Case Study: Temperature Information Application 1081 21.8 User-Defined Types in Web Services 1091 22 Networking: Streams-Based Sockets and Datagrams1106 22.1 Introduction 1107 22.2 Establishing a Simple Server (Using Stream Sockets) 1108 22.3 Establishing a Simple Client (Using Stream Sockets) 1110 22.4 Client/Server Interaction with Stream-Socket Connections 1111 22.5 Connectionless Client/Server Interaction with Datagrams 1120 22.6 Client/Server Tic-Tac-Toe Using a Multithreaded Server 1125 23 Data Structures and Collections 1145 23.1 Introduction 1146 23.2 Self-Referential Classes 1146 23.3 Linked Lists 1148 23.4 Stacks 1160 23.5 Queues 1165 23.6 Trees 1168 23.6.1 Binary Search Tree of Integer Values 1170 23.6.2 Binary Search Tree of IComparable Objects 1177 23.7 Collection Classes 1185 23.7.1 Class Array 1185 23.7.2 Class ArrayList 1188 23.7.3 Class Stack 1194 23.7.4 Class Hashtable 1198 24 Accessibility 1212 24.1 Introduction 1213 24.2 Regulations and Resources 1214 24.3 Web Accessibility Initiative 1216 24.4 Providing Alternatives for Images 1216 24.5 Maximizing Readability by Focusing on Structure 1218 24.6 Accessibility in Visual Studio .NET 1218 24.6.1 Enlarging Toolbar Icons 1219 24.6.2 Enlarging the Text 1220 24.6.3 Modifying the Toolbox 1221 24.6.4 Modifying the Keyboard 1221 24.6.5 Rearranging Windows 1222 24.7 Accessibility in C# 1224 24.8 Accessibility in XHTML Tables 1230 24.9 Accessibility in XHTML Frames 1234 XVI Contents 24.10 Accessibility in XML 1235 24.11 Using Voice Synthesis and Recognition with VoiceXML™ 1235 24.12 CallXML™ 1243 24.13 JAWS® for Windows 1248 24.14 Other Accessibility Tools 1249 24.15 Accessibility in Microsoft® Windows® 2000 1251 24.15.1 Tools for People with Visual Impairments 1252 24.15.2 Tools for People with Hearing Impairments 1254 24.15.3 Tools for Users Who Have Difficulty Using the Keyboard 1255 24.15.4 Microsoft Narrator 1258 24.15.5 Microsoft On-Screen Keyboard 1261 24.15.6 Accessibility Features in Microsoft Internet Explorer 5.5 1262 24.16 Internet and World Wide Web Resources 1264 A Operator Precedence Chart 1273 B Number Systems (on CD) 1275 B.1 Introduction 1276 B.2 Abbreviating Binary Numbers as Octal Numbers and Hexadecimal Numbers 1279 B.3 Converting Octal Numbers and Hexadecimal Numbers to Binary Numbers 1281 B.4 Converting from Binary, Octal or Hexadecimal to Decimal 1281 B.5 Converting from Decimal to Binary, Octal, or Hexadecimal 1282 B.6 Negative Binary Numbers: Two’s Complement Notation 1283 C Career Opportunities (on CD) 1289 C.1 Introduction 1290 C.2 Resources for the Job Seeker 1291 C.3 Online Opportunities for Employers 1292 C.4 Recruiting Services 1297 C.5 Career Sites 1298 C.6 Internet and World Wide Web Resources 1303 D Visual Studio .NET Debugger 1311 D.1 Introduction 1312 D.2 Breakpoints 1313 D.3 Examining Data 1315 D.4 Program Control 1318 D.5 Additional Method Debugging Capabilities 1322 D.6 Additional Class Debugging Capabilities 1324 E Generating Documentation in Visual Studio (on CD) 1329 E.1 Introduction 1330 E.2 Documentation Comments 1330 E.3 Documenting C# Source Code 1331 Contents XVII E.4 Creating Comment Web Pages 1339 E.5 Creating XML Documentation Files 1341 F ASCII Character Set 1348 G Unicode® (on CD) 1349 G.1 Introduction 1350 G.2 Unicode Transformation Formats 1351 G.3 Characters and Glyphs 1352 G.4 Advantages and Disadvantages of Unicode 1353 G.5 Unicode Consortium’s Web Site 1353 G.6 Using Unicode 1355 G.7 Character Ranges 1357 H COM Integration (on CD) 1362 H.1 Introduction 1362 H.2 ActiveX Integration 1364 H.3 DLL Integration 1367 H.4 Internet and World Wide Web Resources 1371 I Introduction to HyperText Markup Language 4: Part 1 (on CD) 1374 I.1 Introduction 1375 I.2 Markup Languages 1375 I.3 Editing HTML 1376 I.4 Common Elements 1376 I.5 Headers 1379 I.6 Linking 1380 I.7 Images 1382 I.8 Special Characters and More Line Breaks 1386 I.9 Unordered Lists 1388 I.10 Nested and Ordered Lists 1389 I.11 Internet and World Wide Web Resources 1392 J Introduction to HyperText Markup Language 4: Part 2 (on CD) 1397 J.1 Introduction 1398 J.2 Basic HTML Tables 1398 J.3 Intermediate HTML Tables and Formatting 1400 J.4 Basic HTML Forms 1403 J.5 More Complex HTML Forms 1406 J.6 Internal Linking 1413 J.7 Creating and Using Image Maps 1416 J.8 <meta> Tags 1418 J.9 frameset Element 1420 [...]... Structured Query Language (SQL) to manipulate databases • Visual Studio NET Debugger Debuggers are programs that help programmers find and correct logic errors in program code Visual Studio NET contains a powerful debugging tool that allows programmers to analyze their programs line-byline as those programs execute In Appendix D, Visual Studio NET Debugger, we explain how to use key debugger features,... class Form, contains a button (Learn More) Visual Inheritance through the Form Designer Class FrmVisualTest, which inherits from class VisualForm.FrmInheritance, contains an additional button Custom control creation Programmer-defined control that displays the current time Custom-control creation Project properties dialog Custom control added to the ToolBox Custom control added to a Form 14 Thread life... Web-based applications to be distributed to consumer-electronic devices, such as cell Preface XXXIX phones and personal digital assistants, as well as to desktop computers The capabilities that Microsoft has incorporated into the NET platform create a new software-development paradigm that will increase programmer productivity and decrease development time New Features in C# How to Program This edition... Button properties and events Program to display hidden text in a password box GroupBox properties Panel properties Creating a Panel with scrollbars Using GroupBoxes and Panels to arrange Buttons CheckBox properties and events Using CheckBoxes to change font styles RadioButton properties and events Using RadioButtons to set message-window options PictureBox properties and events Using a PictureBox to. .. versions and can span many years If programmers document software code and methods, other programmers working on the application can learn and understand the logic underlying the code, thus saving time and avoiding misunderstandings To automate documenting programs, Visual Studio NET provides an XML tool for C# programmers Appendix E, XML Documentation, explains how a programmer can insert comments in... still emphasizing procedural programming The leading-edge courses were using object-oriented C++, but these courses generally mixed a substantial amount of procedural programming with object-oriented programming— something that C++ lets programmers do Many instructors now are emphasizing a pure object-oriented programming approach This book—the first edition of C# How to Program and the second text... principles of computer programming and of the C# language, including control structures, object-oriented programming, C# class libraries, graphical-user-interface concepts, event-driven programming and more After mastering the material in this book, students will be well-prepared to program in C# and to employ the capabilities of the NET platform Multimedia-Intensive Communications People want to communicate... allows programmers to build Web documents that respond to client requests To enable interactive Web pages, server-side programs process information users input into HTML forms ASP NET is a significant de- Preface XL parture from previous versions of ASP, allowing developers to program Webbased applications using the powerful object-oriented languages of NET ASP NET also provides enhanced visual programming... object-oriented programming features This text offers a rich presentation of object-oriented programming Chapter 8, Object-Based Programming, introduces how to create classes and objects These concepts are extended in Chapter 9, Object-Oriented Programming: Inheritance, which discusses how programmers can create new classes that “absorb” the capabilities of existing classes Chapter 10, Object-Oriented Programming:... Brontë Welcome to C# and the world of Windows, Internet and World-Wide-Web programming with Visual Studio and the NET platform! This book is the second in our new NET How to Program series, which presents various leading-edge computing technologies in the context of the NET platform C# is the next phase in the evolution of C and C++ and was developed expressly for Microsoft’s NET platform C# provides . the class-average problem. 111 4.9 Class-average program with sentinel-controlled repetition. 112 4.10 Pseudocode for examination-results problem. 118 4.11 C# program for examination-results. foreground. 52 3 Introduction to C# Programming 3.1 Our first program in C#. 60 3.2 Visual Studio .NET-generated console application. 65 3.3 Execution of the Welcome1 program. 66 3.4 Printing on. repetition to solve the class-average problem. 107 4.7 Class average program with counter-controlled repetition. 107 4.8 Pseudocode algorithm that uses sentinel-controlled repetition to solve

Ngày đăng: 28/04/2014, 15:33

Từ khóa liên quan

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

Tài liệu liên quan