Visual C# 2005 Demystified. McGraw-Hill

Visual C# 2005 Demystified. McGraw-Hill

Now pay Easier and Secure using Paypal

Read more

by Jeff Kent

This book was composed with Adobe® InDesign® CS Mac

Project Editor Samik Roy Chowdhury (Sam), Acquisitions Coordinator Alexander McDonald, Technical Editor Ron Petrusha, Copy Editor Bart Reed, Proofreader Debbie Liehs, Indexer WordCo Indexing Services, Composition International Typesetting and Composition, Illustration International Typesetting and Composition, Cover Series Design Margaret Webster-Shapiro, Cover Illustration Lance Lekander

e-books shop
Visual C# 2005 Demystified

About the Author
Jeff Kent is an Associate Professor of Computer Science at Los
Angeles Valley College in Valley Glen, California. He teaches a
number of programming languages, including C#, Visual Basic,
C++, Java, and—when he's feeling masochistic—Assembler. He
also manages a network for a Los Angeles law firm whose
employees are guinea pigs for his applications, and as an attorney
gives advice to young attorneys whether they want to hear it or
not. He also has written several books on computer programming,
recently Visual Basic. NET: A Beginner's Guide and C++
Demystified for McGraw-Hill, and wrote Visual Basic 2005
Demystified concurrently with this book.

Jeff has had a varied career—or careers. He graduated from
UCLA with a Bachelor of Science degree in economics and then
went on to obtain a Juris Doctor degree from Loyola (Los Angeles)
School of Law and to practice law. During this time, when
personal computers were still a gleam in Bill Gates's eye, Jeff was
also a professional chess master, earning a third place finish in
the United States Under-21 Championship and, later, an
international title.

Jeff does find time to spend with his wife, Devvie, which is not
difficult since she is also a computer science professor at Valley
College. In addition to his other career pursuits, he has a part-time
job as personal chauffeur for his teenage daughter Emily (his
older daughter Elise now has her own driver's license), and what
little spare time he has, he enjoys watching international chess
tournaments on the Internet. His goal is to resume running
marathons, since otherwise, given his losing battle to lose weight,
his next book may be Sumo Wrestling Demystified.

I would like to dedicate this book to the two most important women
in my life, my mom, Beatrice Baumgarten Kent, who gave up her
career as a chemist for the even more important career of a mom;
and my wife, Devvie Schneider Kent, who, in addition to being my

best friend and lover, also is the #1 expert in C# at our home.

It seems obligatory in acknowledgments for authors to thank their
publishers (especially if they want to write for them again), but I
really mean it. This is my sixth book for McGraw-Hill, and I hope
there will be many more. It truly is a pleasure to work with
professionals who are nice people as well as very good at what
they do (even when what they are very good at is keeping
accurate track of the deadlines I miss).

I first want to thank Wendy Rinaldi, who got me started with
McGraw-Hill back in 1998 (has it been that long?). Wendy was
also my first acquisitions editor. She has since received several
well-deserved promotions, but is still my acquisitions editor.
Indeed, this book was launched through a telephone call with
Wendy at the end of a vacation with my wife Devvie, who, being in
earshot, and with an are-you-insane tone in her voice, asked
incredulously "You're writing another book?" I replied, "Of course
not, honey … " She interjected, "That's a relief!" I then continued,
"… I'm writing two books. " (I wrote Visual Basic 2005 Demystified
concurrently with this book).

I must also thank my Acquisitions Coordinator, Alexander
McDonald, and my Project Editor, Samik Roy Chowdhury (Sam).
Both were unfailingly helpful and patient, while still keeping me on
track in this deadline sensitive business (e.g., I'm so sorry you
broke both your arms and legs; you'll still have the next chapter
turned in by this Friday, right?").

Bart Reed did the copyediting. He was kind about my obvious
failure during my school days to pay attention to my grammar
lessons. He improved what I wrote while still keeping it in my
words (that way if something is wrong it is still my fault).
Ron Petrusha was my technical editor. Ron's suggestions were
quite helpful and added a lot of value to this book.

There were many other talented people working behind the
scenes who also helped get this book out to press, and as in an
Academy Award speech, I can't list them all. That doesn't mean I
don't appreciate all their hard work, because I do.
I truly thank my wife Devvie, who in addition to being my wife, best
friend (maybe my only one), and partner (I'm leaving out lover
because computer programmers aren't supposed to be interested
in such things), tolerated my incessant muttering about
unreasonable chapter deadlines and merciless editors (sorry,
Alex) while excusing myself from what she wanted to do (or
wanted me to do). Similarly, I would like to give thanks to my
daughters Elise and Emily and my mom, Bea Kent, for tolerating
my absent-mindedness while I was preoccupied with
unreasonable chapter deadlines and merciless editors (starting to
notice a pattern here?). I also should thank my family in advance
for not having me committed when I talk about writing my next book.

One of my favorite movie lines is in Rocky III when Mr. T
(playing a boxer called Clubber Lang), who had beaten up
Rocky badly in their first fight, says before their rematch, "Fool,
you never should have come back."

Visual Studio must be saying this to me. A few years ago I
wrote a book, Visual Basic .NET: A Beginner's Guide, timed to
be on the bookshelves for the release of Visual Basic. NET, a
component of Visual Studio NET. Writing such a "day and date"
book is added pressure, especially given that Microsoft is
famous (or infamous) for last-minute changes from their most recent beta.

I must have a short memory or be a slow learner. With the next
major change in Visual Studio, version 2005, here I go again
writing another "day and date" book (actually two of them, as mentioned later).

Why did I Write This Book?
Given my griping about writing another "day and date" book,
you may legitimately wonder why I wrote this book. I assure you
that the reason was not because I thought it would get me
riches, fame, or beautiful women. I may be misguided, but I'm
not completely delusional or, in the case of my wife's reaction to
the beautiful women part, suicidal.

To be sure, there likely will be many introductory-level books on
Visual C# 2005. Nevertheless, I wrote this book because I
believe I bring a different and, I hope, valuable perspective.
As you may know from my author biography, I teach computer
science at Los Angeles Valley College, a community college in
the San Fernando Valley area of Los Angeles, where I grew up
and have lived most of my life. I also write computer programs,
but teaching programming has provided me with insights into
how students learn that I could never obtain from just writing
programs. These insights are gained not just from answering
student questions during lectures. I spend hours each week in
our college's computer lab helping students with their programs,
and more hours each week reviewing and grading their
assignments. Patterns emerge regarding which teaching
methods work and which don't, the order in which to introduce
programming topics, the level of difficulty at which to introduce a
new topic, and so on. I joke with my students that they are my
beta testers in my neverending attempt to become a better
teacher, but there is much truth in that joke.

Additionally, my beta testers… err, students, seem to complain
about the textbook no matter which book I adopt. Many ask me
why I don't write a book they could use to learn C#. They may
be saying this to flatter me (I'm not saying it doesn't work), or for
the more sinister reason that they will be able to blame the
teacher for a poor book as well as poor instruction.

Nevertheless, having written other books, these questions
planted in my mind the idea of writing a book that, in addition to
being sold to the general public, also could be used as a
supplement to a textbook.

Who should Read This Book
Anyone who will pay for it! Just kidding, although no buyers will
be turned away.

It is hardly news that publishers and authors want the largest
possible audience for their books. Therefore, this section of the
introduction usually tells you this book is for you, whoever you
may be and whatever you do. However, no programming book
is for everyone. For example, if you exclusively create game
programs using Java, this book may not be for you (though
being a community college teacher I may be your next customer
if you create a space beasts vs. community college administrators game).

Although this book of course is not for everyone, it very well
may be for you. Many people need or want to learn C#, either
as part of a degree program, job training, or even a hobby.
Unfortunately, many books don't make learning C# any easier,
throwing at you a veritable telephone book of complexity and
jargon. By contrast, this book, as its title suggests, is designed
to "demystify" C#. Therefore, it goes straight to the core
concepts and explains them in logical order and in plain English.

What This Book Covers
I strongly believe that the best way to learn programming is to
write programs. The concepts covered by the chapters in this
book are illustrated by programs you can write using tested and
thoroughly explained code. You can run this code yourself and
also use it as the basis for writing further programs that expand
on the covered concepts.

Because, in my opinion, the best way to learn programming is to
write programs, the first part of this book is designed to get you
up and running with Visual C# 2005. Chapter 1 is titled "Getting
Started with Your First Windows Program." The first step in
programming in Visual C# 2005 is to obtain and install it. This
chapter advises you how. The chapter then shows you how you
can create your first Visual C# 2005 project. This chapter
concludes by explaining core concepts such as what a
computer program is, what a programming language is, and
how your code is translated for the computer.

Chapter 1 shows you how to create a working Windows
application without having to write any code. However, you will
need to write code for even the simplest program. Therefore,
Chapter 2, "Writing Your First Code," is about just that. This
chapter explains key programming concepts, such as classes,
objects, and properties, as well as gives you a tour of the Visual
C# 2005 Integrated Development Environment (IDE). The
chapter then describes the event-driven nature of a Windows
application. The chapter finally shows you how to put this theory
into practice by creating an event procedure.

Chapters 1 and 2 focus on the form, perhaps the most
important part of a Windows application's graphical user
interface (GUI). However, a form cannot possibly meet all the
requirements of a Windows application. For example, the form
does not have the functionality to permit the typing of text, listing
of data, selecting of choices, and so forth. You need other,
specialized controls for that additional functionality. Indeed, the
form's primary role is to serve as a host, or container, for other
controls that enrich the GUI of Windows applications, such as
menus, toolbars, buttons, text boxes, and list boxes. Chapter 3,
titled "Controls," explains how to add controls to your form and
manipulate their properties. This chapter then uses a project to
demonstrate how you can use a control's events in an application.

Now that you are up and running with Visual C# 2005, the next
part of this book covers the building blocks of your
programs—variables, data types and operators—starting with
Chapter 4, "Storing Information—Data Types and Variables."
Most computer programs store information, or data. Data comes
in different varieties, such as numeric or text. The type of
information, whether numeric, text, or Boolean, is referred to as
the data type, and often is stored in a variable, which not only
reserves the amount of memory necessary to store information,
but also provides you with a name by which that information
later may be retrieved. Finally, this chapter covers constants,
which are similar to variables, but differ in that their initial value
never changes while the program is running.

As a former professional chess player, I have marveled at the
ability of chess computers to play world champions on even
terms. The reason the chess computers have this ability is
because they can calculate far more quickly and accurately than
we can. Chapter 5, "Letting the Program Do the
Math—Arithmetic Operators," covers arithmetic operators,
which we use in code to harness the computer's calculating capabilities.
Now that we have covered the programming building blocks, it
is time to use them in the next part of this book, which concerns
controlling the flow of your program. As programs become more
sophisticated, they often branch in two or more directions based
on whether a condition is true or false. For example, although a
calculator program would use the arithmetic operators you learn
about in Chapter 5, your program first needs to determine
whether the user has chosen addition, subtraction,
multiplication, or division before performing the indicated
arithmetic operation. Chapters 6, "Making
Comparisons—Comparison and Logical Operators," introduces
comparison and logical operators, which are useful in
determining a user's choice. Chapter 7, "Making Choices—if
and switch Case Control Structures," introduces the if and
switch statements, which are used to direct the path the code
will follow based on the user's choice.
When you were a child, your parents may have told you not to
repeat yourself. However, sometimes your code needs to repeat
itself. For example, if an application user enters invalid data,
your code may continue to ask the user whether they want to
retry or quit until the user either enters valid data or quits.
Chapter 8, "Repeating Yourself—Loops and Arrays," introduces
loops, which are used to repeat code execution until a condition
is no longer true. This chapter then discusses arrays. Unlike the
variables we had covered thus far in the book, which may hold
only one value at a time, arrays may hold multiple values at one
time. Additionally, arrays work very well with loops.

This book is a few hundred pages long. Imagine how much
harder this book would be to understand if it consisted of only
one, very long chapter, rather than being divided into multiple
chapters, with each one divided into sections? Chapter 9,
"Organizing Your Code with Methods," shows you how you
similarly can divide up your code into separate methods. This
has advantages in addition to making your code easier to
understand. For example, if a method performs a specific task,
such as sending output to a printer, which is performed several
times in a program, you only need to write once in a method the
code necessary to send output to the printer. Then you can call
that method each time you need to perform that task.
Otherwise, the code necessary to send output to the printer
would have to be repeated each time that task was to be
performed. Further, if you later have to fix a bug in how you
perform that task, or simply find a better way to perform the
task, you only have to change the code in one place rather than many.

The next part of this book focuses on the graphical user
interface (GUI), starting with Chapter 10, "Helper Forms." Up
until now, our applications have had one form that serves as the
main application window. This one form may be sufficient for a
simple application, but as your applications become more
sophisticated, the main application form will become unable to
perform all the tasks required by the application and need help
from other forms. This chapter shows you how to create and
use two dialog forms that will be workhorses in your
applications—a built-in dialog form, the message box, and
programmer-designed dialog forms. Although these dialog
forms are helpful, they also present programming challenges
involving communication between the main form and the dialog
form. For example, the main form needs to know which button
was clicked on the dialog form, and should execute different
code depending on which button was clicked. Additionally,
because the dialog form contains controls, the main form needs
to know and take actions based on what the application user
typed, checked, or selected in the controls in the dialog form.
This chapter will show you how to solve these programming challenges.

Application users give commands to an application, such as to
open, save, or close a file, print a document, and so on, through
the GUI of the application. Chapter 11, "Menus," and Chapter
12, "Toolbars," cover the three most common GUI elements
through which application users give commands to an
application: the menu, shortcut or context menus, and toolbars.
Additionally, commands such as Cut, Copy, and Paste often
may be duplicated in a menu, a context menu, and a toolbar,
providing the application user with the convenience of three
different ways to perform the same command. However, you
don't want to write the same code three times, so these
chapters show you how to connect corresponding items in
menus, context menus, and toolbars so they each execute the same code.

When I was finished writing this book for the evening, I closed
Microsoft Word, and maybe even shut down my computer. Of
course, the next evening I did not have to start over; what I had
written the previous evening had been saved. However, up until
now the programs in this book don't save data so that it will be
available even after the applications exit. The next part of this
book shows you how to save data. Chapter 13, "Accessing Text
Files," explains how to write code that reads from and writes to
a text file. This chapter also shows you how to add to your
program Open and Save dialog boxes, such as those used in
sophisticated programs like Microsoft Word, so you can open a
text file to read from it, and save to a text file to write to it.
Chapter 14, "Databases," explains how to write programs that
access information stored in a database.
Throughout this book we have been writing Windows
applications, which to be sure are heavily used. However, many
of us are interacting ever more frequently with the subject of
Chapter 15, "Web Applications." This chapter shows you how to
create a web application that displays information from a
database, similar to the Windows application you created in Chapter 14.

How to Read This Book
I have organized this book to be read from beginning to end.
Although this may seem patently obvious, my students often
express legitimate frustration about books (or teachers) that, in
discussing a programming concept, mention other concepts that
are covered several chapters later or, even worse, not at all.
Therefore, I have endeavored to present the material in a linear,
logical progression. This not only avoids the frustration of
material that is out of order, but also enables you in each
succeeding chapter to build on the skills you learned in the preceding chapters.

Special Features
Each chapter has detailed code listings so you can put into
practice what you have learned. My overall objective is to get
you up to speed quickly, without a lot of dry theory or
unnecessary detail. So let's get started. It's easy and fun to write C# programs.

Table of Contents
Chapter 1
-Getting Started with Your First Windows Program
Chapter 2
-Writing Your First Code
Chapter 3
Chapter 4
-Storing Information—Data Types and Variables
Chapter 5
-Letting the Program Do the Math—Arithmetic Operators
Chapter 6
-Making Comparisons—Comparison and Logical Operators
Chapter 7
-Making Choices—If and Switch Control Structures
Chapter 8
-Repeating Yourself—Loops and Arrays
Chapter 9
-Organizing Your Code with Methods
Chapter 10
-Helper Forms
Chapter 11
Chapter 12
Chapter 13
-Accessing Text Files
Chapter 14
Chapter 15
-Web Applications
Final Exam


e-books shop

Purchase Now !
Just with Paypal

Product details
 402 p
 File Size
 10,544 KB
 File Type
 PDF format
 2006 by The McGraw-Hill Companies 

═════ ═════