C# Programming: From Problem Analysis to Program Design. Fourth Edition

Similar documents
Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Microsoft. Microsoft Visual C# Step by Step. John Sharp

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

Visual C# 2008 How to Program, 3/E Outline

You must pass the final exam to pass the course.

CHAPTER 1: INTRODUCING C# 3

OVERVIEW ENVIRONMENT PROGRAM STRUCTURE BASIC SYNTAX DATA TYPES TYPE CONVERSION

Visual Basic 2008 How to Program, 4/E Outline

Contents. Illustrations. 1 Introduction to Computers, the Internet, the Web and C# 1

CHAPTER 1: INTRODUCTION TO THE IDE 3

Contents. Using Interpreters... 5 Using Compilers... 5 Program Development Life Cycle... 6

Microsoft Visual C# Step by Step. John Sharp

Deitel Series Page How To Program Series

Variable Scope The Main() Function Struct Functions Overloading Functions Using Delegates Chapter 7: Debugging and Error Handling Debugging in Visual

Introduction to C++/CLI 3. What C++/CLI can do for you 6 The rationale behind the new syntax Hello World in C++/CLI 13

"Charting the Course... MOC A Introduction to Web Development with Microsoft Visual Studio Course Summary

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Chapters and Appendix F are PDF documents posted online at the book s Companion Website (located at

Microsoft Visual Studio 2010

Before You Begin. and Visual Basic 1

C# 2008 and.net Programming for Electronic Engineers - Elektor - ISBN

Contents. Before You Begin. Object Technology: A Brief Review

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Chapters are PDF documents posted online at the book s Companion Website (located at

Beginning ASP.NET. 4.5 in C# Matthew MacDonald

DOT NET SYLLABUS FOR 6 MONTHS

Object-Oriented Programming in C# (VS 2015)

.NET Advance Package Syllabus

Object-Oriented Programming in C# (VS 2012)

Diploma in Microsoft.NET

DOT NET Syllabus (6 Months)

A Web-Based Introduction

Programming C# 5.0. Ian Griffiths O'REILLY' Beijing Cambridge * Farnham Kbln Sebastopol Tokyo

Migrate Your Skills to Microsoft.NET Framework 2.0 and 3.0 using Visual Studio 2005 (C#)

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Course Syllabus C # Course Title. Who should attend? Course Description

"Charting the Course... Java Programming Language. Course Summary

Introduction to Programming Microsoft.NET Framework Applications with Microsoft Visual Studio 2005 (C#)

10264A CS: Developing Web Applications with Microsoft Visual Studio 2010

Introduction to Microsoft.NET Framework Programming using VS 2005 (C#)

Contents Chapter 1 Introduction to Programming and the Java Language

Before You Begin 1 Graphing Application 1 Introducing Computers, the Internet and Visual Basic.NET

Subject to Change Drawing Application 1 Introducing Computers, the Internet and C#

Absolute C++ Walter Savitch

Contents. 1 Introduction to Computers, the Internet. Before You Begin

"Charting the Course... MOC A Developing Data Access Solutions with Microsoft Visual Studio Course Summary

3 Welcome Application 41 Introduction to Visual Programming

Course Hours

Introduction to Web Development with Microsoft Visual Studio 2010

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

ощ 'ршорвшэш! цвн-эориэу ощ 'sajbpossv # PIPG DUJ 'ssjmoossv ^ PIPG pipa w н OX ЛЮН VAV

Murach s Beginning Java with Eclipse

Mastering VB.NET using Visual Studio 2010 Course Length: 5 days Price: $2,500

C++/CLI in Action NISHANT SIVAKUMAR MANNING. Greenwich (74 w. long.)

Fundamentals of the Java Programming Language

Introduction to Programming Using Java (98-388)

CHAPTER 1: GETTING STARTED WITH ASP.NET 4 1

Introduction to Microsoft.NET Programming Using Microsoft Visual Studio 2008 (C#) Course Overview. Prerequisites. Audience.

SECURED PROGRAMMING IN.NET DETAILED TRAINING CONTENT INDUSTRIAL TRAINING PROGRAM ( )

PESIT- Bangalore South Campus Hosur Road (1km Before Electronic city) Bangalore

ASP.NET 2.0 p. 1.NET Framework 2.0 p. 2 ASP.NET 2.0 p. 4 New Features p. 5 Special Folders Make Integration Easier p. 5 Security p.

.NET FRAMEWORK. Visual C#.Net

Table Of Contents VISUAL BAISC 2005 FOR BEGINNERS

10267A CS: Developing Web Applications Using Microsoft Visual Studio 2010

Introduction... xxi. Chapter 1: Introducing Visual Basic In Depth... 2

Table of Contents. Preface... xxi

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

The C# Programming Language. Overview

"Charting the Course... MOC Programming in C# with Microsoft Visual Studio Course Summary

10267 Introduction to Web Development with Microsoft Visual Studio 2010

2609 : Introduction to C# Programming with Microsoft.NET

This page intentionally left blank

ALPHAPRIMETECH 112 New South Road, Hicksville, NY 11801

DE Introduction to Web Development with Microsoft Visual Studio 2010

Apex TG India Pvt. Ltd.

MyProgram m i ng Lab. get with the programming. Through the power of practice and immediate personalized

JAVA CONCEPTS Early Objects

Acknowledgments Introduction. Chapter 1: Introduction to Access 2007 VBA 1. The Visual Basic Editor 18. Testing Phase 24

COPYRIGHTED MATERIAL. Contents. Chapter 1: Introducing Microsoft Expression Web 1. Chapter 2: Building a Web Page 21. Acknowledgments Introduction

Contents. Acknowledgments

Coding Faster: Getting More Productive with Microsoft Visual

Excel Programming with VBA (Macro Programming) 24 hours Getting Started

.Net Technologies. Components of.net Framework

DEVELOPING WEB APPLICATIONS WITH MICROSOFT VISUAL STUDIO Course: 10264A; Duration: 5 Days; Instructor-led

Problem Solving with C++

Preface. The Purpose of this Book and Its Audience. Coverage and Approach

M Introduction to C# Programming with Microsoft.NET - 5 Day Course

Introduction to JavaScript p. 1 JavaScript Myths p. 2 Versions of JavaScript p. 2 Client-Side JavaScript p. 3 JavaScript in Other Contexts p.

CHAPTER 1: VISUAL STUDIO

Introduction. Part I: Silverlight Fundamentals for ASP.NET Developers 1

.NET, C#, and ASP.NET p. 1 What Is.NET? p. 2 The Common Language Runtime p. 2 Introducing C# p. 3 Introducing ASP.NET p. 4 Getting Started p.

Windows Presentation Foundation Programming Using C#

DEVELOPING WINDOWS APPLICATIONS WITH MICROSOFT VISUAL STUDIO 2010

Developing Web Applications Using Microsoft Visual Studio 2008 SP1

COURSE OUTLINE: OD10267A Introduction to Web Development with Microsoft Visual Studio 2010

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

Object-Oriented Programming and Data Structures

Advanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition

Computer Programming C++ (wg) CCOs

CERTIFICATE IN WEB PROGRAMMING

Transcription:

C# Programming: From Problem Analysis to Program Design Fourth Edition

Preface xxi INTRODUCTION TO COMPUTING AND PROGRAMMING 1 History of Computers 2 System and Application Software 4 System Software 4 Application Software 6 Software Development Process 6 Steps in the Program Development Process 7 Programming Methodologies 13 Structured Procedural Programming 14 Object-Oriented Programming 16 Evolution of C# and.net 19 Programming Languages 19.NET 21 Why C#? 23 Types of Applications Developed with C# 24 Web Applications 24 Windows Applications 25 Console Applications 26 Exploring the First C# Program 27 Elements of a C# Program 28 Comments 28 Using Directive 30 Namespace 32 Class Definition 32

viii I C# Programming: From Problem Analysis to Program Design, Fourth Edition Main() Method 33 Method Body Statements 34 Compiling, Building, and Running an Application 38 Typing Your Program Statements 38 Compilation and Execution Process 39 Compiling the Source Code Using Visual Studio IDE 39 Debugging an Application 45 Syntax Errors 45 Run-time Errors 47 Creating an Application 47 Coding Standards 52 Pseudocode 52 Resources 53 Quick Review 53 Exercises 56 Programming Exercises 61 M DATA TYPES AND EXPRESSIONS 65 Data Representation 66 Bits 66 Bytes 66 Binary Numbering System 66 Character Sets 69 Kilobyte, Megabyte, Gigabyte, Terabyte, Petabyte... 70 Memory Locations for Data 70 Identifiers 71 Variables 75 Literal Values 75 Types, Classes, and Objects 76 Types 76 Classes 77 Objects 78 Predefined Data Types 79 Value Types 80

Table of Contents I ix Integral Data Types 82 Floating-Point Types 85 Decimal Types 86 Boolean Variables 87 Declaring Strings 88 Making Data Constant 88 Assignment Statements 89 Basic Arithmetic Operations 92 Increment and Decrement Operations 95 Compound Operations 98 Order of Operations 100 Mixed Expressions 102 Casts 103 Formatting Output 104 Width Specifier 109 Coding Standards 119 Naming Conventions 119 Spacing Conventions 119 Declaration Conventions 120 Resources 120 Quick Review 120 Exercises 121 Programming Exercises 127 METHODS AND BEHAVIORS 131 Anatomy of a Method 132 Modifiers 134 Return Type 137 Method Name 138 Parameters 138 Method Body 139 Calling Class Methods 141 Predefined Methods 143 Writing Your Own Class Methods 157 Void Methods 157 Value-Returning Method 159

x I C# Programming: From Problem Analysis to Program Design, Fourth Edition Types of Parameters 164 Named and Optional Parameters 169 Default Values with Optional Parameters 170 Named Parameters 171 Coding Standards 180 Naming Conventions 180 Spacing Conventions 180 Declaration Conventions 180 Commenting Conventions 181 Resources 181 Quick Review 181 Exercises 182 Programming Exercises 189 CREATING YOUR OWN CLASSES 191 The Object Concept 192 Private Member Data 193 Constructor 197 Writing Your Own Instance Methods 200 Accessor 200 Mutators 201 Other Instance Methods 202 Property 202 ToString() Method 204 Calling Instance Methods 206 Calling the Constructor 206 Calling Accessor and Mutator Methods 208 Calling Other Instance Methods 209 Testing Your New Class 210 Coding Standards 235 Naming Conventions 235 Classes 235 Properties 235 Methods 236

Table of Contents I xi Constructor Guidelines 236 Spacing Conventions 236 Resources 236 Quick Review 237 Exercises 238 Programming Exercises 244 MAKING DECISIONS 247 Boolean Expressions 248 Boolean Results 248 Conditional Expressions 249 Equality, Relational, and Logical Tests 250 Short-Circuit Evaluation 258 Boolean Data Type 260 if...else Selection Statements 261 One-Way if Statement 261 Two-Way if Statement 266 Nested if...else Statement 273 Switch Selection Statements 279 Ternary Operator? : 283 Order of Operations 285 Coding Standards 298 Guidelines for Placement of Curly Braces 299 Guidelines for Placement of else with Nested if Statements 299 Guidelines for Use of White Space with a Switch Statement 299 Spacing Conventions 300 Advanced Selection Statement Suggestions 300 Resources 300 Quick Review 301 Exercises 302 Programming Exercises 310

xii I C# Programming: From Problem Analysis to Program Design, Fourth Edition PV REPEATING INSTRUCTIONS 313 mm Why Use a Loop? 314 Using the While Statement 314 Counter-Controlled Loop 316 Sentinel-Controlled Loop 321 State-Controlled Loops 332 Using the for Statement Loop 335 Using the Foreach Statement 342 Using the Do...while Structure 343 Nested Loops 346 Recursive Calls 351 Unconditional Transfer of Control 354 Continue Statement 355 Deciding Which Loop to Use 356 Coding Standards 370 Guidelines for Placement of Curly Braces 371 Spacing Conventions 371 Advanced Loop Statement Suggestions 371 Resources 372 Quick Review 372 Exercises 373 Programming Exercises 379 DARRAYS 383 Array Basics 384 Array Declaration 385 Array Initializers 388 Array Access 390 Sentinel-Controlled Access 394 Using Foreach with Arrays 395 Array Class 396 Arrays as Method Parameters 401 Pass by Reference 401 Array Assignment 405 Params Parameters 406

Table of Contents I xiii Arrays in Classes 408 Array of User-Defined Objects 410 Arrays as Return Types 410 Coding Standards 428 Guidelines for Naming Arrays 428 Advanced Array Suggestions 428 Resources 429 Quick Review 429 Exercises 430 Programming Exercises 437 ADVANCED COLLECTIONS 439 Two-Dimensional Arrays 440 Rectangular Array 440 Jagged Array 450 Multidimensional Arrays 450 ArrayList Class 455 String Class 459 Other Collection Classes 465 BitArray 466 Hashtable 467 Queue 469 Stack 470 Coding Standards 479 Guidelines for Naming Collections 479 Advanced Array Suggestions 479 Resources 479 Quick Review 480 Exercises 481 Programming Exercises 488 9 INTRODUCTION TO WINDOWS PROGRAMMING Contrasting Windows and Console Applications Graphical User Interfaces 493 494 496

xiv I C# Programming: From Problem Analysis to Program Design, Fourth Edition Elements of Good Design 500 Consistency 500 Alignment 500 Avoid Clutter 501 Color 501 Target Audience 501 Using C# and Visual Studio to Create Windows-Based Applications 502 Windows Forms 505 Windows Forms Properties 505 Inspecting the Code Generated by Visual Studio 511 Windows Forms Events 515 Controls 517 Placing, Moving, Resizing, and Deleting Control Objects 520 Methods and Properties of the Control Class 521 Derived Classes of the System.Windows.Forms.Control Class 524 Coding Standards 567 Guidelines for Naming Controls 567 Resources 567 Quick Review 568 Exercises 569 Programming Exercises 574 Wfji PROGRAMMING BASED ON EVENTS 577 UmI Delegates 578 Defining Delegates 578 Creating Delegate Instances 579 Using Delegates 580 Relationship of Delegates to Events 583 Event Handling in C# 583 Event-Handler Methods 584 ListBox Control Objects 585 Creating a Form to Hold ListBox Controls 585 ListBox Event Handlers 588 Multiple Selections with a ListBox Object 589

Table of Contents I xv ComboBox Control Objects 601 Adding ComboBox Objects 602 Handling ComboBox Events 602 Registering a KeyPress Event 603 Programming Event Handlers 603 MenuStrip Control Objects 605 Adding Menus 606 Adding Predefined Standard Windows Dialog Boxes 610 CheckBox and RadioButton Objects 618 CheckBox Objects 618 Adding CheckBox Objects 619 Registering CheckBox Object Events 619 Wiring One Event Handler to Multiple Objects 621 GroupBox Objects 622 RadioButton Objects 622 Adding RadioButton Objects 622 Registering RadioButton Object Events 624 Windows Presentation Foundation (WPF) 633 TabControl Objects 639 Coding Standards 680 Resources 680 Quick Review 680 Exercises 682 Programming Exercises 688 ADVANCED OBJECT-ORIENTED PROGRAMMING FEATURES 691 Object-Oriented Language Features 692 Component-Based Development 693 Inheritance 694 Inheriting from the Object Class 695 Inheriting from Other.NET FCL Classes 695 Creating Base Classes for Inheritance 696 Overriding Methods 699 Creating Derived Classes 700

xvi I C# Programming: From Problem Analysis to Program Design, Fourth Edition Making Stand-Alone Components 705 Creating a Client Application to Use the DLL 715 Using ILDASM to View the Assembly (Optional) 719 Abstract Classes 721 Abstract Methods 721 Sealed Classes 724 Sealed Methods 725 Partial Classes 725 Creating Partial Classes 726 Interfaces 726 Defining an Interface 727 Implementing the Interface 728.NET Framework Interfaces 733 Polymorphism 734 Polymorphic Programming in.net 736 Generics 737 Generic Classes 737 Generic Methods 741 Dynamic 742 Dynamic data type 743 var data type 744 Coding Standards 764 Resources 765 Quick Review 765 Exercises 767 Programming Exercises 772 PM DEBUGGING AND HANDLING EXCEPTIONS 775 Errors 776 Run-Time Errors 777 Debugging in C# 778 Exceptions 786 Raising an Exception 790 Bugs, Errors, and Exceptions 791

Table of Contents I xvii Exception-Handling Techniques 793 Try...Catch...Finally Blocks 794 Exception Object 798 Exception Classes 799 Derived Classes of the Base Exception Class 799 ApplicationException Class 800 SystemException Class 801 Filtering Multiple Exceptions 802 Throwing an Exception 809 Input Output (10) Exceptions 810 Coding Standards 828 Resources 829 Quick Review 829 Exercises 830 Programming Exercises 835 WORKING WITH FILES 837 System.10 Namespace 838 File and Directory Classes 840 File Class 840 Directory Class 844 Filelnfo and Directorylnfo Classes 845 File Streams 848 Writing Text Files 851 Reading Text Files 856 Adding a Using Statement 860 Random Access 863 BinaryReader and BinaryWriter Classes 863 Other Stream Classes 869 FileDialog Class 870 Coding Standards 884 Resources 884 Quick Review 884 Exercises 885 Programming Exercises 890

xviii I C# Programming: From Problem Analysis to Program Design, Fourth Edition IH WORKING WITH DATABASES 893 U Database Access 894 Database Management Systems 894 ADO.NET 895 Data Providers 896 Connecting to the Database 899 Retrieving Data from the Database 901 Processing the Data 905 Updating Database Data 913 Using Datasets to Process Database Records 913 Data Source Configuration Tools 921 Add New Data Source 921 Dataset Object 931 TableAdapterManager 941 DataSet Designer 942 Connecting Multiple Tables 953 Displaying Data Using Details View 959 Language-Integrated Query (LINQ) 962 Query Expressions 963 Implicitly Typed Local Variables 966 LINQ with Databases 966 LINQ to SQL 968 Coding Standards 969 Resources 969 Quick Review 969 Exercises 971 Programming Exercises 976 ffil WEB-BASED APPLICATIONS 979 IEi Web-Based Applications 980 Web Programming Model 980 Static Pages 981 Dynamic Pages 984

Table of Contents I xix ASP.NET 986 Visual Studio for Web Development 986 ASP.NET Programming Models 987 Web Forms Page 988 Creating an ASP.NET Web Forms Site 988 Master Pages 993 Cascading Style Sheet (CSS) 997 ASP.NET Empty WebSite 1001 Controls 1004 HTML Controls 1004 HTML Server Controls 1008 Web Forms Standard Server Controls 1012 Available Web Forms Controls 1012 Web Forms Controls of the Common Form Type 1014 Adding Common Form-Type Controls 1018 Validation, Custom, and Composite Controls 1021 Validation Controls 1021 Calendar Control 1026 GridView Control 1033 AccessDataSource 1039 Using Visual Tools to Connect 1040 Setting the Visibility Property 1045 Other Controls 1047 Web Services 1050 Web Services Protocols 1050 Windows Communication Foundation (WCF) 1052 Smart Device Applications (Optional) 1052 Windows 7.x Phone 1053 Silverlight 1054 Creating a Smart Device Application for Windows 7.x Phones 1054 Windows 8 Phone Apps 1061 Creating a Windows 8 Phone App 1063 XML 1064 Code-Behind File 1065 XAML Code 1067 Running the App 1068 Deploying to an Emulator 1068 Deploying to a Device 1071

xx I C# Programming: From Problem Analysis to Program Design, Fourth Edition Coding Standards 1073 Resources 1074 Quick Review 1075 Exercises 1076 Programming Exercises 1081 APPENDIX A: VISUAL STUDIO CONFIGURATION 1083 Customizing the Development Environment 1083 Environment 1085 Projects and Solutions 1088 Text Editor 1089 Debugging 1093 HTML Designer 1093 Windows Forms Designer 1094 Other Options Settings 1095 Choose Toolbox Items 1096 Customize the Toolbars 1097 APPENDIX B: CODE EDITOR TOOLS 1099 Code Snippets 1099 Refactoring 1101 Extrace Method 1102 Rename 1104 Other Refactoring Options 1105 Working with Class Diagrams 1106 Class Details View 1107 Using the Class Diagram to Add Members 1108 Other Code Editor Tips 1109 APPENDIX C: CHARACTER SETS 1111 APPENDIX D: OPERATOR PRECEDENCE 1113 APPENDIX E: C# KEYWORDS 1115 GLOSSARY 1117 INDEX 1131