Table of
Contents
Learn to Program with C# Using the .Net Batch Compiler
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 OUR 'CLIENT'
WE MEET WITH OUR CLIENT
THE SYSTEMS DEVELOPMENT LIFE CYCLE (SDLC)
PHASE 1: THE PRELIMINARY INVESTIGATION
PHASE 2: ANALYSIS PHASE
PHASE 3: DESIGN PHASE
Output Design
Input Design
Processing Design
PHASE 4: DEVELOPMENT PHASE
PHASE 5: IMPLEMENTATION PHASE
PHASE 6: AUDIT AND MAINTENANCE PHASE
WHERE TO FROM HERE?
SUMMARY
CHAPTER 2--- GETTING COMFORTABLE WITH C#
GETTING COMFORTABLE WITH C#
WRITING OUR FIRST C# PROGRAM
Create the Source File with a file name extension of .cs
Compile the C# Source File into a MSIL File
Common Compiler Errors
Oops: Invalid Option or Argument
Oops: Can’t Find the Compiler
Run the C# Program
ELEMENTS OF A C# PROGRAM
Program Comments
The Class: The Essence of a C# Program
The Main() Method
The Using Keyword
CHAPTER 3---DATA
COMPUTER DATA
VARIABLES
Our first variable: The Local Variable
Declaring a Variable
Assigning a Value to a Variable
Declaration and Assignment Combined
A Quick Look at Instance and Static Variables
Variable Scope and Lifetime
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
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 (!)
SUMMARY
CHAPTER 4---SELECTION STRUCTURES
SELECTION STRUCTURES
THE SEQUENCE STRUCTURE---FALLING ROCK
THE C# SELECTION STRUCTURE---THE IF STATEMENT
GETTING INPUT INTO YOUR PROGRAM
THE IF…ELSE STATEMENT
STRING RESPONSE;
THE SWITCH STATEMENT
AN INTRODUCTION TO WINDOWS
WINDOWS OUT
CONTINUING WITH THE GRADES CALCULATION PROJECT
SUMMARY
CHAPTER 5---LOOPS
WHY LOOPS?
THE FOR LOOP
Variations on the For Loop Theme
WHILE LOOPS
The While Loop
Do-While Loop
ADDING A LOOP TO THE GRADES CALCULATION PROJECT
SUMMARY
CHAPTER ---CREATING YOUR OWN METHODS
MODULAR PROGRAMS ARE EASIER TO MAINTAIN AND UNDERSTAND
WHAT IS A METHOD?
CREATING YOUR OWN METHODS…
METHOD HEADER
ACCESS MODIFIERS
Public Access Modifier
Private Access Modifier
Protected Access Modifier
Internal Access Modifier
The Return Type
Method Parameters and Arguments
In C#, by Default, Arguments are passed by Value
USING METHODS TO FINE TUNE YOUR CODE
METHOD OVERLOADING
CHAPTER 7---CREATING OBJECTS FROM INSTANTIABLE CLASSES
CREATING OBJECTS FROM INSTANTIABLE CLASSES
CREATING CLASSES IS AN EXTENSION OF MODULAR PROGRAMMING
Objects Have Data that Simulation Object Characteristics
Objects Have Behavior
CREATING OBJECTS FROM YOUR CLASSES
Changing an Object's Attributes
Calling an Object's Methods
CREATING MULTIPLE OBJECTS FROM YOUR CLASSES
CLASS CONSTRUCTORS
CLASS CONTRACTS
OVERLOADED CONSTRUCTORS
CLASS VARIABLES
DESTROYING AN OBJECT---THE C# GARBAGE COLLECTOR
CLASS DESTRUCTORS
SUMMARY
CHAPTER 8---CONTROLLING ACCESS TO THE DATA IN YOUR OBJECT
CONTROLLING ACCESS TO YOUR OBJECT'S DATA
INSTANCE VARIABLES--PUBLIC OR PRIVATE?
CREATING A PROPERTY: GET() AND SET() ACCESSOR METHODS
set() Accessor Methods
get() Accessor Methods
LET'S ANALYZE THE GRADES CALCULATION PROJECT FOR DATA INTEGRITY
A surprise visit from Frank Olley
SUMMARY
CHAPTER 9---INHERITANCE AND INTERFACES
INHERITANCE
BEFORE INHERITANCE CAME ALONG...
CREATING CLASSES FROM OTHER CLASSES USING INHERITANCE
THE BASE CLASS (PARENT CLASS)
THE DERIVED CLASS (CHILD CLASS)
PLANNING YOUR OBJECT HIERARCHY IN ADVANCE
ABSTRACT METHODS AND CLASSES
INTERFACES ARE NOT INHERITANCE
CREATING A BASE CLASS AND DERIVED CLASSES IN THE GRADES CALCULATION PROJECT
SUMMARY
CHAPTER 10---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
USING AN ARRAY FOR AVERAGING
A PROBLEM WITH OUR ARRAY
MULTIPLE DIMENSIONED ARRAYS
CREATING ARRAYS OF OBJECTS
SUMMARY
CHAPTER 11---EXCEPTION HANDLING
COMMON BEGINNER ERRORS
COMPILER ERRORS
C# is Case Sensitive
Forgetting the Simicolon 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 (=)
Not Initialzing a Variable Defined in a Method Before that Variable is Used in the Method Body.
Forgetting to Specify a Return Type for a Method You Write
Forgetting to Specify the Return Value for a Method You Write
Returning the Wrong Type of Return Value for a Method You Write
Returning a Value from a Method Whose Return Type is Void
Creating an Overloaded Method with What You Believe to Be a Different Signature
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
DIVISION BY ZERO
C# ERROR HANDLING
C# EXCEPTIONS
Ignore the Exception
Handle the Exception with Try-Catch-Finally Blocks
Can We Modify the Grades Calculation Project?
SUMMARY
CHAPTER 12---DEVELOPING A GRAPHICAL USER INTERFACE
BUILDING A GRAPHICAL USER INTERFACE
DESIGNING OUR GUI
CREATING OUR GUI
Setting Up the Top-Level Component: The Form
Adding Other Objects to the Form
Create the GUI for the Grades Calculation Project
SUMMARY
CHAPTER 13---EVENT HANDLING IN C#
C# EVENT HANDLING
WHAT'S AN EVENT?
WHAT'S AN EVENT PROCEDURE?
IMPLEMENTING A SIMPLE EVENT HANDLER IN YOUR CODE
Creating Our First Event Handler
Creating Our Event Handler To Handle Events from More Than One Object
IMPLEMENTING EVENT PROCEDURES IN THE GRADES CALCULATION PROJECT
TESTING THE PROGRAM
DELIVERING AND IMPLEMENTING THE GRADES CALCULATION PROJECT IN THE ENGLISH DEPARTMENT
SUMMARY