C# Programming, Third Edition. Course Technology

C# Programming, Third Edition. Course Technology

Now pay Easier and Secure using Paypal

Read more

 From Problem Analysis to Program Design

Barbara Doyle

Executive Editor: Marie Lee, Acquisitions Editor: Amy Jollymore, Senior Product Manager: Alyssa Pratt, Editorial Assistant: Jacqueline Lacaire, Content Project Manager: Jennifer Feltri, Art Director: Faith Brosnan, Print Buyer: Julio Esperas, Cover Designer: Saizon Design, Cover Photo: © iStockphoto.com, Copyeditor: Andrea Schein, Indexer: Sharon Hilgenberg, Compositor: Integra


1. Introduction to Computing and Programming
2. Data Types and Expressions
3. Methods and Behaviors
4. Creating Your Own Classes
5. Making Decisions
6. Repeating Instructions
8. Advanced Collections
9. Introduction to Windows Programming
10. Programming Based on Events
11. Advanced Object-Oriented Programming Features
12. Debugging and Handling Exceptions
13.Working with Files
14.Working with Databases
15.Web-Based Applications

e-books shop
C# Programming:
From Problem Analysis to Program Design
Third Edition

I would like to express my gratitude for the opportunity to complete the third edition of this
book. Like the other editions, it was a huge undertaking for me. Special thanks go out to Alyssa Pratt, Senior Product Manager at Cengage Learning, for her positive comments, guidance, and support. She was a pleasure to work with again on this new edition. I am grateful to the Quality Assurance team members who verified that each of the examples and
exercise solutions worked properly.Also thanks to the Content Manager and Copy
Editor, Jennifer Feltri and Andrea Schein, who provided great suggestions as we
progressed with the project.

I am very grateful to the following reviewers for their uplifting comments and
suggestions for improvements:
Richard Mowe: St. Cloud State University
Mike Nerino: Alvernia University
Beryl Shaw: Baruch College:CUNY
Gary Smith: Paradise Valley Community College
I hope that the reviewers will see that many of their suggestions were implemented.
The textbook is much improved because of their contributions.
I would also like to thank my family for their understanding while I was writing.
Thanks to my parents, Howard and Alma King, who have always been
sources of encouragement and inspiration. And finally, a big thank you goes out
to David for the support he provided during the completion of this project.

C# Programming: From Problem Analysis to Program Design requires no previous introduction
to programming and only a mathematical background of high school algebra. The
book uses C# as the programming language for software development; however, the basic
programming concepts presented can be applied to a number of other languages. Instead of
focusing on the syntax of the C# language, this book uses the C# language to present general
programming concepts. It is the belief of the author that once you develop a thorough understanding of one programming language, you can effectively apply those concepts to other
programming languages.

Why C#?
C# is gaining tremendous popularity in the industry. C# is a true object-oriented language
that includes a rich set of instruction statements. C# was the language used for development
of much of .NET, the Microsoft programming paradigm that includes a collection of more
than 2,000 predefined classes that make up the Framework Class Library (FCL).Thus, C# has
access to a large collection of predefined classes similar to those available to Java. C# provides
tools that make it easy to create graphical user interfaces—similar to the tools Visual Basic
programmers have employed for years. C# also provides the pure data crunching horsepower
to which C/C++ programmers have become accustomed. But unlike other languages, C#
was designed from scratch to accommodate Internet and Windows applications. C# is an elegant
and simple object-oriented language that allows programmers to build a breadth of
applications. For these reasons, C# was chosen as the language for this book.

Going Beyond the Traditional CS1 Course
This book was written for the Computer Science 1 (CS1) student and includes all of the
basic programming constructs normally covered in the traditional CS1 foundation course
for the Computer Science curriculum. It includes lots of examples and figures illustrating
basic concepts. But this book goes beyond what is traditionally found in most CS1 textbooks
and, because of the inclusion of a number of advanced applications, this textbook
could also be used in an intermediate course for students who have already been exposed to
some programming concepts.

Advanced Topics
After building a solid programming foundation, this book presents rapid application development techniques that can be used to build a number of advanced types of applications.
Generics, dynamic data types, abstract classes, interfaces, and a number of advanced objectoriented concepts are all introduced. Solutions involving multidimensional arrays and other
advanced collection classes are demonstrated. Illustrating the drag-and-drop construction
approach used with Visual Studio,Windows and Web applications are created. Readers are
introduced to the event-driven programming model, which is based on interactively capturing
and responding to user input on Windows and Web forms. In the past, CS1 courses and
even CS2 courses did not include this model.

For first-time programmers, this book is unusual in introducing applications that retrieve and
update data in databases such as those created using Microsoft Access. A number of visual
development tools are illustrated to connect to data sources. Other interesting topics include
retrieving data using Language-Integrated Query (LINQ), developing stand-alone .dll components (class libraries), and programming applications for mobile devices such as personal
digital assistants (PDAs) and smart phones.All of these advanced features are discussed after the
reader has gained a thorough understanding of the basic components found in programming languages.

C# Programming: From Problem Analysis to Program Design, Third Edition, has been considerably revised and updated to reflect the latest release of Visual C# and .NET 4.0. Additional advanced object-oriented concepts are included. All screenshots are updated to the Visual Studio 2010 IDE.The new edition provides more coverage of visual tools used for development. Heavier emphasis is focused on using the IDE’s drag-and-drop techniques to create
data-bound applications.Windows applications are designed using the Windows Forms paradigm
and readers are also introduced to building applications using the Windows Presentation
Foundation (WPF). Additional Web applications are designed using ASP.NET master pages
and the templates available in Visual Studio. In addition to these changes the third edition
includes several new topics.The following summarizes the changes in the third edition.
1. Chapter have a new section titled “Coding Standards,” which provides a summary of
acceptable conventions or guidelines pertaining to the chapter’s 
topics often focusing on style issues.
2. New Web site resources are added as references to the chapters.
3. Chapters 1 and 2 were combined and readers begin developing applications immediately
in the first chapter.
4. A full chapter is devoted to methods and behaviors before readers are introduced
to writing their own classes.
5. Two full chapters are devoted to collection classes. Readers are first introduced
to array basics in Chapter 7. Chapter 8 builds on this knowledge to enable readers
to create multidimensional arrays,Arraylists, and others collections like hash tables,
queues, and stacks.
6. Chapter 9 includes several new Windows forms controls. Readers are also introduced
to creating Windows application using the 
Windows Presentation Foundation (WPF) in Chapter 10.
7. Chapter 11,Advanced Object-Oriented Programming Features,was expanded to
illustrate the new dynamic typing, which is included with C# 4.0. Sealed classes are
added and the section on generics is expanded.
8. Chapter 14 also introduces LINQ and the set of query operators used to query
and manipulate data independent of data sources. Implicitly type variables and
query expressions are introduced. Chapter 14 places a heavier emphasis on illustrating
the visual tools that can be used to create applications that display and update table data.
9. Designing new ASP.NET Web Sites with Visual Studio 2010 creates a master page
and a Cascading Style Sheet (CSS) file. 
Both these file types are illustrated in this new edition in Chapter 15.
10. Appendix A, Customizing the Visual Studio Development Environment, is updated to
highlight features available in Visual Studio 2010.Appendix B, Code Editor Tools,
includes more illustrations and figures. It also highlights working with class diagrams.

A problem-solving methodology based on object-oriented software development is introduced
early and used throughout the book. Programming Examples are presented at the
end of each chapter, and each example follows a consistent approach: analyzing the problem
specifications, designing a solution, implementing the design, and verifying or validating the
solution structures.

The author believes that the best way to learn to program is to experience programming.
This assumption drives the material presented in this textbook. As new concepts are introduced,
they are described using figures and illustrations. Examples are shown and discussed
as they relate to the concept being presented.With a hands-on approach to learning, readers
practice and solidify the concepts presented by completing the end of the chapter exercises.
Readers are also encouraged throughout the book to explore and make use of the more
than 2,000 classes that make up the Framework Class Library (FCL).

Every chapter begins with a list of objectives and a short overview of the previous chapter.
Text in each chapter is supplemented with figures and tables to help visual learners grasp the
concepts being presented. Each chapter is sprinkled with useful tips and hints on the concepts
being presented, and code snippets are embedded as new concepts are introduced in
each chapter. In addition, each chapter contains complete working programs illustrating an
application using C#. Every chapter ends with a Coding Standards section, which provides a
summary of acceptable conventions or guidelines pertaining to the chapter’s topics that focus
on style issues.A summary of the major points covered in that chapter and review exercises
in both objective and subjective formats are included. Every chapter contains 10 programming
exercises that give readers an opportunity to experience programming.

Using this Book for Two Different Courses
Although this book is primarily intended for a beginning programming course, it will also
work well in an intermediate course. For courses introducing students to programming,
Chapters 1 through 8 should be covered in detail. Depending on how quickly students are
able to grasp the material, the course could end in any of the chapters following Chapter 8.
For example, ending with Chapter 9, Introduction to Windows Programming, would give
students an opportunity to get excited about continuing their work in programming in
upcoming semesters.

For an intermediate course, where the first course was taught using a different language, the
last part of Chapter 1 along with Appendices A and B could be read to orient the readers to
running an application using Visual Studio. Students could be encouraged to scan Chapters 2
through 7 and review Chapter 8 more extensively. Scanning these chapters, students could
compare and contrast the details of the C# language with the programming languages they
already know.

For the intermediate course where the first course was taught using C#, Chapters 4, 7, and 8
should be reviewed, because topics covered in these chapters—Creating your Own Classes
and Arrays—are often more difficult for the student to grasp. The remainder of the book
beginning in Chapter 9 would be included for the intermediate course.

Overview of the Chapters
Chapter 1 briefly reviews the history of computers and programming languages including
the evolution of C# and .NET.This chapter explains the difference between structured and
object-oriented programming and includes the software development methodology used
throughout the remainder of the book.This chapter describes the different types of applications
that can be developed using C#. It discusses the basic elements found in a C# program
and illustrates how to compile, run, and debug an application.

The focus in Chapter 2 is data types and expressions. Readers gain an understanding of how
types, classes, and objects are related.They also learn how to perform arithmetic procedures
on the data, how to display formatted data, and how expressions are evaluated using operator
precedence. Chapter 3 extends the manipulation of the data through introducing methods
and behaviors of the data. Readers learn to write statements that call methods and to write
their own class methods.They learn how to pass arguments to methods that return values
and to those that do not. Readers learn to create your own classes in Chapter 4.This chapter introduces the components of a class including the data, property, and method members. Special methods, including constructors, are written. Chapters 5 and 6 introduce control structures that alter the sequential flow of execution. Selection control constructs are introduced in Chapter 5. One-way, multiway, switch, and ternary operators used to make decisions are illustrated. Looping is introduced in Chapter 6.The rich set of iteration operators including while, for, do while, and foreach are explored. Recursive solutions are also explored.
Chapter 7 discusses arrays. This chapter describes how to declare and perform compile-time
initialization of array elements.The Array class and its many members are introduced. Methods
of the string and ArrayList classes are included in Chapter 8. Multidimensional arrays and other
collection classes, including stacks, queues, and hash tables are also introduced in Chapter 8.
Chapters 9 and 10 present a different way of programming, which is based on interactively
responding to events. A number of classes in the FCL that are used to create Windows
applications are introduced. Elements of good design are discussed in Chapter 9. Delegates
are also explored in Chapter 9.Visual Studio’s drag-and-drop approach to rapid application
development is introduced and used in these chapters.The Windows Presentation Foundation
(WPF) is also introduced in Chapter 10 as an alternative approach to Win Forms for
creating Windows applications. Advanced object-oriented programming features are the focus of Chapter 11.You are introduced to component-based development and learn how to create your own class library files. Inheritance, interfaces, abstract classes, sealed classes, generic types, partial classes, and polymorphic programming are discussed in detail. Advanced features such as overriding, overloading, and the use of virtual methods are also included in Chapter 11.You also investigate static versus dynamic typing in Chapter 11.
Chapter 12 discusses debugging and exception handling techniques. The chapter introduces
one of the tools available in Visual Studio, the Debugger, which can be used to
observe the run-time environment, take an up-close look at the code, and locate logic
errors. The try…catch…finally block is discussed for handling exceptions. In addition to
discussing .NET exception classes, custom exceptions are designed.
Chapter 13 presents the basics of creating, opening, closing, reading, and writing files.The
major classes used to work with file and directory systems are introduced. Chapter 14 introduces
a number of new namespaces collectively called ADO.NET, which consists of a managed
set of library classes that enables interaction with databases.The chapter illustrates how
ADO.NET classes are used to retrieve and update data in databases.The visual programming
tools and wizards available with Visual Studio, which simplify accessing data, are covered in
this chapter.The Language-Integrated Query (LINQ) is also introduced in Chapter 14.
The focus of Chapter 15 is on Web applications. Readers explore how the design of Webbased
applications differs from Windows applications.They discover the differences between
static and dynamic Web pages and how HTML and Web server controls differ. Master pages
and Cascading Style Sheets are introduced.Also included in Chapter 15 is an introduction to
mobile applications that can be viewed with small personal devices such as a personal digital
assistant (PDA). Chapter 15 illustrates how validation controls can be used to check users’
input values and shows how the ADO.NET classes, introduced in Chapter 14, can also be
used with Web applications to access database records.

Appendix A presents suggestions for customizing the appearance and behavior of the
Integrated Development Environment (IDE).Appendix B discusses the Code Editor features
of Visual Studio. Code snippets and refactoring are described. These new features improve
programmer productivity by reducing the number of keystrokes required to enter program
statements. This appendix also illustrates developing applications visually using Class
Diagrams.Appendix C lists the Unicode and ASCII (American Standard Code for Information
Interchange) character sets.Appendix D shows the precedence of the C# operators and
Appendix E lists the C# keywords.

Every chapter in this book includes the following features.These features are both conducive
to learning in the classroom and enable you to learn the material at your own pace.
■ Four-color interior design shows accurate C# code and related comments.
■ Learning objectives offer an outline of the concepts discussed in detail in the chapter.
■ Hundreds of visual diagrams throughout the text illustrate difficult concepts.
■ Syntax boxes show the general form for different types of statements.
■ Numbered examples illustrate the key concepts with their relevant code, and the
code is often followed by a sample run.An explanation following that describes the
functions of the most difficult lines of code.
■ Notes highlight important facts about the concepts introduced in the chapter.
■ Numerous tables are included that describe and summarize information compactly for easy viewing.
■ A new Coding Standards section provides a summary of acceptable conventions or
guidelines pertaining to the chapter’s topic.
■ Internet sites listed including tutorials that can be used to enhance concepts are presented.
■ Programming Examples are complete programs featured at the end of the chapter.
The examples contain the distinct stages of preparing a problem specification, analyzing
the problem, designing the solution, and coding the solution.
■ Quick Reviews offer a summary of the concepts covered in the chapter.
■ Exercises further reinforce learning and ensure that students have, in fact, absorbed the material.
■ Programming Exercises challenge students to write C# programs with a specified outcome.
■ The glossary at the end of the book lists all the key terms in alphabetical order along
with definitions for easy reference.
From beginning to end, the concepts are introduced at a pace that is conducive to learning.
The writing style of this book is simple and straightforward, and it parallels the teaching style
of a classroom.The concepts introduced are described using examples and small programs.
The chapters have two types of programs.The first type includes small programs that are part
of the numbered examples and are used to explain key concepts. This book also features
numerous case studies called Programming Examples. These Programming Examples are
placed at the end of the chapters to pull together many of the concepts presented throughout
the chapter.The programs are designed to be methodical and workable. Each Programming
Example starts with a Problem Analysis and is then followed by the Algorithm Design. Every
step of the algorithm is then coded in C#. In addition to teaching problem-solving techniques,
these detailed programs show the user how to implement concepts in an actual C#
program. Students are encouraged to study the Programming Examples very carefully in
order to learn C# effectively.

All source code and solutions have been written, compiled, and tested by quality assurance
with Visual Studio Professional 2010.
Microsoft®Visual C#® can be packaged with this text. Please contact your Course Technology
Sales Representative for more information.

Table of Contents
1. Introduction to Computing and Programming 1
History of Computers 2
System and Application Software 6
System Software 7
Application Software 8
Software Development Process 8
Steps in the Program Development Process 9
Programming Methodologies 15
Structured Procedural Programming 15
Object-Oriented Programming 17
Evolution of C# and .NET 20
Programming Languages 20
.NET 21
Why C#? 23
Types of Applications Developed with C# 24
Web Applications 25
Windows Applications 26
Console Applications 27
Exploring the First C# Program 28
Elements of a C# Program 28
Comments 29
Using Directive 30
Namespace 32
Class Definition 32
Main( ) Method 33
Method Body—Statements 34
Compiling, Building, and Running an Application 38
Typing Your Program Statements 38
Compilation and Execution Process 38
Compiling the Source Code Using Visual Studio IDE 39
Debugging an Application 45
Syntax Errors 45
Run-time Errors 46
Creating an Application 47
Programming Example: ProgrammingMessage 47
Resources 52
Quick Review 53
Exercises 55
Programming Exercises 61
2. Data Types and Expressions 65
Data Representation 66
Bits 66
Bytes 66
Binary Numbering System 66
Character Sets 68
Kilobyte, Megabyte, Gigabyte,Terabyte, Petabyte… 69
Memory Locations for Data 70
Identifiers 70
Variables 73
Literal Values 74
Types, Classes, and Objects 75
Types 75
Classes 75
Objects 76
Predefined Data Types 77
Value Types 78
Integral Data Types 79
Floating-Point Types 81
Decimal Types 83
Boolean Variables 84
Declaring Strings 84
Making Data Constant 85
Assignment Statements 86
Basic Arithmetic Operations 89
Increment and Decrement Operations 91
Compound Operations 94
Order of Operations 96
Mixed Expressions 98
Casts 99
Formatting Output 100
Programming Example: CarpetCalculator 104
Coding Standards 112
Naming Conventions 112
Spacing Conventions 113
Declaration Conventions 113
Resources 114
Quick Review 114
Exercises 115
Programming Exercises 120
3. Methods and Behaviors 123
Anatomy of a Method 124
Modifiers 126
Return Type 129
Method Name 130
Parameters 130
Method Body 131
Calling Class Methods 132
Predefined Methods 134
Writing Your Own Class Methods 147
Void Methods 148
Value-Returning Method 149
Types of Parameters 155
Named and Optional Parameters 160
Default Values with Optional Parameters 160
Named Parameters 161
Programming Example: JoggingDistance 162
Coding Standards 170
Naming Conventions 170
Spacing Conventions 171
Declaration Conventions 171
Commenting Conventions 171
Resources 171
Quick Review 172
Exercises 173
Programming Exercises 179
4. Creating Your Own Classes 181
The Object Concept 182
Private Member Data 183
Writing Your Own Instance Methods 187
Constructor 187
Accessor 190
Mutators 191
Other Instance Methods 191
Property 192
Calling Instance Methods 195
Calling the Constructor 195
Calling Accessor and Mutator Methods 197
Calling Other Instance Methods 198
Testing Your New Class 199
Programming Example: RealEstateInvestment 212
Coding Standards 221
Naming Conventions 221
Classes 221
Properties 221
Methods 222
Constructor Guidelines 222
Spacing Conventions 222
Resources 222
Quick Review 223
Exercises 224
Programming Exercises 229
5. Making Decisions 233
Boolean Expressions 234
Boolean Results 234
Conditional Expressions 235
Equality, Relational, and Logical Tests 236
Short-Circuit Evaluation 243
Boolean Data Type 245
if...else Selection Statements 245
One-Way if Statement 246
Two-Way if Statement 250
Nested if…else Statement 256
Switch Selection Statements 261
Ternary Operator ? : 266
Order of Operations 267
Programming Example: SpeedingTicket 269
Coding Standards 278
Guidelines for Placement of Curly Braces 278
Guidelines for Placement of else with Nested if Statements 278
Guidelines for Use of White Space with a Switch Statement 279
Spacing Conventions 279
Advanced Selection Statement Suggestions 279
Resources 280
Quick Review 280
Exercises 282
Programming Exercises 290
6. Repeating Instructions 293
Why Use a Loop? 294
Using the While Statement 294
Counter-Controlled Loop 296
Sentinel-Controlled Loop 300
State-Controlled Loops 309
Using the For Statement Loop 312
Using the Foreach Statement 319
Using the Do...while Structure 320
Nested Loops 323
Recursive Calls 328
Unconditional Transfer of Control 330
Continue Statement 331
Deciding Which Loop to Use 333
Programming Example: LoanApplication 333
Coding Standards 346
Guidelines for Placement of Curly Braces 346
Spacing Conventions 346
Advanced Loop Statement Suggestions 346
Resources 347
Quick Review 347
Exercises 348
Programming Exercises 354
7.Arrays 357
Array Basics 358
Array Declaration 359
Array Initializers 362
Array Access 364
Sentinel-Controlled Access 368
Using Foreach with Arrays 369
Array Class 370
Arrays as Method Parameters 375
Pass by Reference 375
Array Assignment 379
Params Parameters 380
Arrays in Classes 382
Array of User-Defined Objects 384
Arrays as Return Types 384
Programming Example: Manatee Application 391
Coding Standards 401
Guidelines for Naming Arrays 401
Advanced Array Suggestions 401
Resources 401
Quick Review 401
Exercises 402
Programming Exercises 409
8. Advanced Collections 411
Two-Dimensional Arrays 412
Rectangular Array 412
Jagged Array 422
Multidimensional Arrays 422
ArrayList Class 427
String Class 430
Other Collection Classes 434
BitArray 435
Hashtable 436
Queue 438
Stack 439
Programming Example:TempAgency Application 441
Coding Standards 448
Guidelines for Naming Collections 448
Advanced Array Suggestions 448
Resources 449
Quick Review 449
Exercises 450
Programming Exercises 457
9. Introduction to Windows Programming 461
Contrasting Windows and Console Applications 462
Graphical User Interfaces 464
Elements of Good Design 468
Consistency 468
Alignment 469
Avoid Clutter 469
Color 469
Target Audience 469
Using C# and Visual Studio to Create Windows-Based Applications 470
Windows Forms 473
Windows Forms Properties 473
Inspecting the Code Generated by Visual Studio 479
Windows Forms Events 483
Controls 485
Placing,Moving, Resizing, and Deleting Control Objects 488
Methods and Properties of the Control Class 489
Derived Classes of the System.Windows.Form.Control Class 491
Programming Example:TempAgency Application 507
Coding Standards 530
Guidelines for Naming Controls 530
Resources 530
Quick Review 530
Exercises 532
Programming Exercises 536
10. Programming Based on Events 539
Delegates 540
Defining Delegates 540
Creating Delegate Instances 541
Using Delegates 542
Relationship of Delegates to Events 544
Event Handling in C# 545
Event-Handler Methods 546
ListBox Control Objects 546
Creating a Form to Hold ListBox Controls 546
ListBox Event Handlers 549
Multiple Selections with a ListBox Object 550
ComboBox Control Objects 560
Adding ComboBox Objects 561
Handling ComboBox Events 562
Registering a KeyPress Event 562
Programming Event Handlers 563
MenuStrip Control Objects 565
Adding Menus 565
Adding Predefined Standard Windows Dialog Boxes 570
CheckBox and RadioButton Objects 578
CheckBox Objects 578
Adding CheckBox Objects 578
Registering CheckBox Object Events 579
Wiring One Event Handler to Multiple Objects 580
GroupBox Objects 581
RadioButton Objects 581
Adding RadioButton Objects 581
Registering RadioButton Object Events 583
Windows Presentation Foundation (WPF) 592
TabControl Objects 598
Programming Example: DinerGui Application 601
Coding Standards 632
Resources 632
Quick Review 633
Exercises 634
Programming Exercises 640
11. Advanced Object-Oriented Programming Features 643
Object-Oriented Language Features 644
Component-Based Development 645
Inheritance 646
Inheriting from the Object Class 646
Inheriting from Other .NET FCL Classes 647
Creating Base Classes for Inheritance 648
Overriding Methods 651
Creating Derived Classes 652
Making Stand-Alone Components 661
Creating a Client Application to Use the DLL 667
Using ILDASM to View the Assembly 671
Abstract Classes 673
Abstract Methods 673
Sealed Classes 675
Sealed Methods 675
Partial Classes 676
Creating Partial Classes 676
Interfaces 676
Defining an Interface 677
Implementing the Interface 678
.NET Framework Interfaces 681
Polymorphism 682
Polymorphic Programming in .NET 683
Generics 684
Generic Classes 684
Generic Methods 689
Dynamic 689
Dynamic data type 690
var data type 691
Programming Example: StudentGov Application 692
Coding Standards 708
Resources 709
Quick Review 709
Exercises 711
Programming Exercises 716
12. Debugging and Handling Exceptions 719
Errors 720
Run-Time Errors 721
Debugging in C# 722
Exceptions 729
Raising an Exception 732
Bugs, Errors, and Exceptions 733
Exception-Handling Techniques 735
Try…Catch…Finally Blocks 735
Exception Object 739
Exception Classes 741
Derived Classes of the Base Exception Class 741
ApplicationException Class 741
SystemException Class 742
Filtering Multiple Exceptions 743
Custom Exceptions 747
Throwing an Exception 750
Input Output (IO) Exceptions 751
Programming Example: ICW WaterDepth Application 753
Coding Standards 767
Resources 767
Quick Review 768
Exercises 769
Programming Exercises 773
13.Working with Files 775
System.IO Namespace 776
File and Directory Classes 777
File Class 778
Directory Class 782
FileInfo and DirectoryInfo Classes 783
File Streams 785
Writing Text Files 788
Reading Text Files 793
Adding a Using Statement 796
Random Access 799
BinaryReader and BinaryWriter Classes 799
Other Stream Classes 806
FileDialog Class 806
Programming Example: ICW WaterDepth File App 809
Coding Standards 819
Resources 819
Quick Review 819
Exercises 820
Programming Exercises 825
14.Working with Databases 827
Database Access 828
Database Management Systems 828
Data Providers 830
Connecting to the Database 833
Retrieving Data from the Database 834
Processing the Data 839
Updating Database Data 846
Using Datasets to Process Database Records 847
Data Source Configuration Tools 854
Add New Data Source 855
Dataset Object 864
DataGridView Control 866
TableAdapterManager 873
DataSet Designer 874
Connecting Multiple Tables 884
Displaying Data Using Details View 889
Language-Integrated Query (LINQ) 893
Query Expressions 893
Implicitly Typed Local Variables 895
LINQ with Databases 896
LINQ to SQL 898
Coding Standards 899
Resources 899
Quick Review 899
Exercises 901
Programming Exercises 906
15.Web-Based Applications 909
Web-Based Applications 910
Web Programming Model 910
Static Pages 911
Dynamic Pages 914
Visual Web Developer 916
ASP.NET Programming Models 916
Web Forms Page 917
Creating a Web Site 918
Master Pages 922
Cascading Style Sheet (CSS) 924
ASP.NET Empty Web Site 928
Controls 930
HTML Controls 931
HTML Server Controls 935
Web Forms Standard Server Controls 939
Available Web Forms Controls 939
Web Forms Controls of the Common Form Type 941
Adding Common Form-Type Controls 945
Validation, Custom, and Composite Controls 948
Validation Controls 948
Calendar Control 952
DataGrid and GridView Controls 958
AccessDataSource 964
Using Visual Tools to Connect 964
Setting the Visibility Property 968
Other Controls 970
Web Services 972
Web Services Protocols 973
Windows Communication Foundation (WCF) 974
Smart Device Applications (Optional) 976
Silverlight 977
Creating a Smart Device Application 978
Coding Standards 983
Resources 984
Quick Review 984
Exercises 986
Programming Exercises 990
APPENDIX A Visual Studio Configuration 993
Customizing the Development Environment 993
Environment 995
Projects and Solutions 998
Text Editor 999
Debugging 1003
HTML Designer 1003
Windows Forms Designer 1004
Other Options Settings 1004
Customize the Toolbars 1005
APPENDIX B Code Editor Tools 1007
Code Snippets 1007
Refactoring 1009
Extract Method 1009
Rename 1011
Other Refactoring Options 1013
Working with Class Diagrams 1013
Class Details View 1014
Using the Class Diagram to Add Members 1015
Other Code Editor Tips 1017
APPENDIX C Character Sets 1019
APPENDIX D Operator Precedence 1021
APPENDIX E C# Keywords 1023
INDEX 1035


e-books shop

Purchase Now !
Just with Paypal

Product details
 1092 p
 File Size
 56,931 KB
 File Type
 PDF format
 2011 Course Technology, Cengage Learning 

═════ ═════