Table of Contents
Learn to Program with Visual C# 2005 Express

CHAPTER 1---WHERE DO I BEGIN? 
WHERE DO WE BEGIN 
PROGRAMMING THE EASY WAY 
PLANNING A PROGRAM IS LIKE PLANNING A HOUSE 
WE RECEIVE A CALL FROM THE CHINA SHOP 
WE MEET WITH OUR CLIENT 
THE SYSTEMS DEVELOPMENT LIFE CYCLE (SDLC) 
PHASE 1: THE PRELIMINARY INVESTIGATION 
PHASE 2: ANALYSIS 
PHASE 3: DESIGN 
Output Design 
Input Design 
Processing Design 
PHASE 4: DEVELOPMENT 
PHASE 5: IMPLEMENTATION 
PHASE 6: AUDIT AND MAINTENANCE 
WHERE TO FROM HERE? 
SUMMARY 

CHAPTER 2---WHAT IS A COMPUTER PROGRAM? 
WHAT IS A COMPUTER? 
DATA 
Bits 
Bytes 
MEMORY 
COMPUTER STORAGE 
RAM VERSUS STORAGE 
WHAT MAKES A COMPUTER PROGRAM RUN? 
A LITTLE COMPUTER HISTORY 
DOS 
Booting DOS 
Running Programs in DOS 
Bad Command or File name 
RAM Use in DOS 
Registers 
The Stack 
Problems with DOS 
MICROSOFT WINDOWS 
The Title Bar 
The Menu Bar 
Windows Behavior 
A MORE IN-DEPTH LOOK AT WINDOWS 
Virtual Memory 
MULTITASKING 
Nonpreemptive Multitasking 
Preemptive Multitasking 
Running Programs in Windows 
Preparing the Windows Program to Run 
Running the Windows Program 
The Windows Handle 
Windows Messages 
The Focus 
WHAT IS A COMPUTER PROGRAM? 
SUMMARY 

CHAPTER 3---GETTING COMFORTABLE WITH C# 
THE VISUAL C# ENVIRONMENT 
PREPARING THE WAY FOR PROGRAMMING 
LET'S START UP C#! 
THE C# PROJECT 
THE IDE 
THE MODES OF C# 
THE C# MENU BAR 
The File Menu 
The Print Menu 
The Edit Menu 
The View Menu 
The Project Menu 
The Build Menu 
The Debug Menu 
The Data Menu 
The Format Menu 
The Tools Menu 
The Window Menu 
The Help Menu 
THE VISUAL C# TOOLBAR 
THE VISUAL C# TOOLBOX 
THE PROPERTIES WINDOW 
SUMMARY 

CHAPTER 4---PROGRAMMING IS EASY 
LESS IS BEST 
C# PROPERTIES, METHODS, AND EVENTS 
C# PROPERTIES 
RUNNING THE CHINA SHOP PROJECT FOR THE FIRST TIME 
PROPERTIES OF THE FORM 
Name of the Form 
Naming Conventions 
Height and Width Properties 
The FormBorderStyle and ControlBox Properties 
The StartPosition Property 
The Text Property 
C# METHODS 
C# EVENTS 
SUMMARY 

CHAPTER 5---BUILDING THE USER INTERFACE 
COMPLETING THE USER INTERFACE 
JOHN SMILEY'S TEN-STEP GUIDE TO SUCCESSFUL INTERFACE DEVELOPMENT 
THE C# TOOLBOX 
THE CHINA SHOP CONTROLS 
CREATION OF THE CHINA SHOP FORM 
The GroupBox Control 
The ListBox Control 
The Label Control 
The Button Control 
The CheckBox Control 
The RadioButton Control 
The PictureBox Control 
The ColorDialog Control 
The Timer Control 
LET'S RUN THE CHINA SHOP PROJECT! 
COMMON PROPERTIES OF THE CONTROLS IN THE CHINA SHOP PROJECT 
The Name Property 
The Text Property 
CHECKBOX PROPERTIES 
BUTTON CONTROL PROPERTIES 
The AcceptButton Property of the Form 
The CancelButton Property of the Form 
COLORDIALOG PROPERTIES 
GROUPBOX PROPERTIES 
PICTUREBOX CONTROL PROPERTIES 
The SizeMode Property 
LABEL PROPERTIES 
The AutoSize Property 
LISTBOX PROPERTIES 
RADIOBUTTON PROPERTIES 
TIMER PROPERTIES 
The Interval Property 
TAB ORDER AND THE TABINDEX PROPERTY 
A SURPRISE VISIT 
SUMMARY 

CHAPTER 6---A FIRST LOOK AT CODING 
EVENTS AND EVENT-DRIVEN PROGRAMMING 
IN THE OLD DAYS... 
THE MODERN APPROACH 
WHAT'S AN EVENT? 
An Event or an Event Procedure? 
An Example of an Event Procedure Stub 
THE EVENTS IN THE CHINA SHOP PROJECT 
The Click Event 
The Load Event 
The SelectedIndexChanged Event 
The Tick Event 
WRITING CODE 
PROGRAM COMMENTS 
WHITESPACE 
A C# CODE OVERVIEW 
The Sequence Structure—Falling Rock 
The Selection Structure 
The Loop Structure 
THE C# DEBUGGER 
The Debug/Immediate Window 
Pausing a C# Program 
The Break Button 
Displaying Values in the Code Window 
The Immediate Window 
The Break Statement 
THE DEBUG MENU 
Step Into 
Run To Cursor 
Step Over 
Step Out 
Set Next Statement 
Show Next Statement 
The Locals Window 
The Watch Window 
Breakpoints 
SUMMARY 

CHAPTER 7---DATA 
COMPUTER DATA 
VARIABLES 
Our First Variable: The Local Variable 
Declaring a Variable 
Assigning a Value to a Variable 
Variable Scope 
The Private Statement 
The Public Statement 
Where Should You Declare a Variable? 
MUST VARIABLES BE INITIALIZED? 
CONSTANTS 
C# DATA TYPES 
NUMERIC DATA TYPES 
sbyte 
byte 
short 
ushort 
int 
uint 
long and ulong 
float 
double 
decimal 
NONNUMERIC DATA TYPES 
bool 
char 
THE STRING OBJECT 
PROPERTY DATA TYPES 
OPERATIONS ON DATA 
ARITHMETIC OPERATIONS 
The Addition Operator 
The Subtraction Operator 
The Multiplication Operator 
The Division Operator 
The Modulus Operator 
The Increment Operator (++) 
The Decrement Operator (--) 
Order of Operations 
COMPARISON OPERATORS 
LOGICAL OPERATORS 
The And Operator (&) 
The Or Operator (|) 
The Not Operator (!) 
How Not to Use Not 
SUMMARY 

CHAPTER 8---SELECTION STRUCTURES 
FALLING ROCK BEHAVIOR 
HOW CAN WE IMPROVE UPON THIS? 
THE C# SELECTION STRUCTURE---THE IF STATEMENT 
IF…ELSE 
IF…ELSE…IF 
THE SWITCH STATEMENT 
THE CHINA SHOP PROJECT 
REVIEWING THE PROTOTYPE 
SUMMARY 

CHAPTER 9---LOOPS 
WHY LOOPS? 
THE FOR LOOP 
Variations on the For Loop Theme 
WHILE LOOPS 
The While Loop 
Do-While Loop 
MR. BULLINA SENDS A SURPRISE 
SUMMARY 

CHAPTER 10---STRING MANIPULATION 
WHAT EXACTLY IS A STRING? 
STRING CONCATENATION 
BREAKING STRINGS APART 
SUMMARY 

CHAPTER 11---ARRAYS 
WHY ARRAYS? 
WHAT'S AN ARRAY? 
DECLARING AND INITIALIZING AN ARRAY 
ADDING DATA TO THE ELEMENTS OF AN ARRAY 
THE WONDERS OF ARRAY PROCESSING 
MULTIPLE DIMENSIONED ARRAYS 
SUMMARY 

CHAPTER 12--- FILE OPERATIONS 
DISK FILE OPERATIONS 
WRITING DATA TO A DISK FILE 
THE STREAMWRITER OBJECT 
The WriteLine Method 
The Write Method 
The Close Method 
READING DATA FROM A DISK FILE 
The ReadLine Method 
ARRAYS AND FILES 
MODIFYING THE CHINA SHOP PROJECT TO INCLUDE ARRAYS 
SUMMARY 

CHAPTER 13---FINISHING THE USER INTERFACE 
WHERE ARE WE NOW? 
DROP-DOWN MENUS 
A FIRST LOOK AT THE MENUSTRIP CONTROL 
Adding Top-Level Menu Items 
Adding Submenu Items 
Deleting Menu Items 
Inserting Menu Items 
MenuItem Properties 
Menu Item Events 
CODING THE MENU ITEM CONTROLS 
MORE ON THE MESSAGEBOX.SHOW METHOD 
THE RETURN VALUE OF THE MESSAGEBOX.SHOW METHOD 
THE BUTTONS ARGUMENT OF THE MESSAGEBOX.SHOW METHOD 
THE ICON ARGUMENT OF THE MESSAGEBOX.SHOW METHOD 
SUMMARY 

CHAPTER 14---ERROR HANDLING 
COMMON BEGINNER ERRORS 
COMPILER ERRORS 
C# is Case Sensitive 
Forgetting the Semicolon at the End of a Statement 
Braces (and Parentheses) Must Occur in Matching Pairs 
Forgetting the Left and Right Parentheses for the Condition in an If Structure 
Confusing the Equality Operator (==) with the Assignment Operator (=) 
Forgetting to Code a Break Statement in a Switch Structure 
RUNTIME ERRORS/LOGIC ERRORS 
Referring to an Element Outside the Array Bounds 
FORGETTING TO INCREMENT A COUNTER VARIABLE 
FORGETTING TO ADD TO AN ACCUMULATOR 
Not providing a way for a while structure to end 
FAILING TO INCLUDE THE USING IO.SYS STATEMENT 
TRYING TO OPEN A FILE FOR READING THAT DOES NOT EXIST 
FORGETTING TO CLOSE A FILE 
YOUR PROGRAM DOESN'T FIND ANY RECORDS 
READING TOO MANY OR TOO FEW FIELDS FROM A DISK FILE 
DIVISION BY ZERO 
C# ERROR HANDLING 
C# EXCEPTIONS 
Ignore the Exception 
Handle the Exception with Try-Catch-Finally Blocks 
ERROR HANDLING IN THE CHINA SHOP PROJECT 
SUMMARY 

CHAPTER 15---CUSTOMIZING YOUR PROGRAM 
WRITING TO THE WINDOWS REGISTRY 
REGISTRY KEYS AND SUBKEYS 
USING SETVALUE TO WRITE TO THE WINDOWS REGISTRY 
USING REGEDIT 
READING FROM THE WINDOWS REGISTRY 
OPTIMIZING C# CODE 
USER-WRITTEN PROCEDURES 
Writing Our Own Procedures 
SUBPROCEDURES IN THE CHINA SHOP PROJECT 
TESTING OUR PROGRAM 
WE MEET AT THE BULLINA CHINA SHOP 
SUMMARY