This book looked interesting as it seemed to be written by someone with a lot of experience teaching. Sometimes it is great to go back to basics, as there is always something new to learn, and I was so right! Here are my notes, source code, screenshots.
Chapter 1 – Getting Started
setting up the IDE.. VS2008 Express. And installing the MSDN library.. 2GB download here: http://www.microsoft.com/downloads/details.aspx?FamilyID=7BBE5EDA-5062-4EBB-83C7-D3C5FF92A373&displaylang=en
Also a tool to take msdn into a chm help file: http://www.codeplex.com/packagethis
Chapter 2 - Understanding Objects
Class eg Person.. a template used to describe an object
properties..that describe the object
methods.. or actions that we associate with the object
Object eg the Person Object for Jack
naming convention
cls - class
txt - textbob
btn - button
good for selecting in the ide
making a blank project
putting in references for winform:
System, System.Drawing, System.Windows.Forms
putting in bootstrapper
change output to winform and tell which startup object asdf
using System;
using System.Windows.Forms;
public class frmMain : Form
{
#region Windows code
private void InitializeComponent()
{
}
#endregion
public frmMain()
{
InitializeComponent();
}
public static void Main()
{
frmMain main = new frmMain();
Application.Run(main);
}
}
3d on labels cool
making a default enter button (acceptbutton)
ctrl x and ctrl d shortcut keys with the ampersand on Text
True Type vs non fonts.. good to make things line up properly.
**screenshot mailing label program
**source code here too … c:\code\oopbook
Part II – Understand C# Syntax
Chapter 3 – Understanding Data Types
Integer Division
.Focus property when coming back from an error
Int.TryParse method to see if it really is an integer
.Visible proerty of a textbox
Floating Point
AcceptButton
StartPosition - CenterScreen
int
float - 32 bit.. F,f
double - 64 bit... this is the usual one.. D,d
Decimal - 128bit (28 digit precision).. M,m
eg int i = 0.5M
**insert source code c:\code\oopbook\ch3IntegerDivision\
Also Fahrehiegh converter:
** put in source code link… c:\code\oopbook\ch3TempConvert
Interesting here was the use of consts…
how a division takes up more cycles, so better not to do 5/9 but to put in the decimal equivalent. The out.. focus when coming back from an error. And unhiding the results box when it needs to be.
bool flag;
double operand1;
double answer;
const double FIVENINTHS = 0.55555555;
const double ZEROFAHRENHEIGHT = 32;
flag = double.TryParse(txtOperand1.Text, out operand1);
if (flag == false)
{
MessageBox.Show("Enter a whole number", "Input Error");
txtOperand1.Focus();
return;
}
answer = FIVENINTHS *(operand1 - ZEROFAHRENHEIGHT);
txtResult.Text = operand1.ToString() + " degressF " + " equals " + answer.ToString() + " degreesC";
txtResult.Visible = true;
Ch4 – Understanding C# Statements
operand eg 10
operator eg +, -, *, /, % these are binary operators
unary
binary
ternary
expression
one or more operands and their associated operator
statements
one or more expressions terminated by a semicolon.
lvalue - location value.. memory address
rvalue - register value..actual value
eg int i
this is defining a variable to be at address 900,000 ie lvalue
i = 10
this is declaring a variable to have an rvalue of 10
if narly bug, hardcode data into the textboxes to make it easy!
10 / 6
avoid magic numbers
use const
Ch5 - Reference Data Types
If you're not going to manipulate data with Maths, store it as a string.
intellisense (expect in Resharper which is clearer)
hand is a property
diamond is a method
Pass by reference vs Pass by Value
Ctrl spacebar to give help on methods/props near current selection.
**insert source…c:\code\oopbook\ch5StringTester
Escape characters eg string message = “this is a \\ backlash, and this is a quote \””;
String literals eg string message = @”Go the the c:\program files\ directory and”;
DateTime reference Objects
**upload source code** c:\code\oopbook\ch5DateTime
Interesting code here is:
txtLongDate.Text = myTime.ToString("D");
Starting the app (everything gets populated automatically without having to press Test)
public frmMain()
{
// 2) place all the label, textbox and button objects in correct positions on the form and set their properties
InitializeComponent();
UpdateTimeInfo(); // 3) set the properties of the objects just created
}
public static void Main()
{
// 1) start here then this goes to constructor now everything is in memory ready to go
frmMain main = new frmMain();
Application.Run(main); // 4) run the app
MessageBox.Show("hello"); // 5) this would only be displayed when Close() is called.
}
Ch6 – Making Decisions In Code
20% of a programs time is spent in initial development
80% of a programs time is spent in testing, debugging, and maintenance
flag = int.TryParse(txtOperand1.Text, out operand1);
don’t need to initialise operand1 to any value.. int operand1 is fine.
**upload code ** c:\code\oopbook\ch6OddOrEven

Interesting here is the .Clear method after the check.
MessageBox.Show("Enter a whole number", "Input Error");
txtOperand1.Clear();
txtOperand1.Focus();
return;
Brackets Style:
K&R (Kernighan and Ritchie… 1978 book on C)
if (x == 2) {
//do something
}
Other style:
if (x == 2)
{
//do something
}
or
if (x == 2)
// do something
the danger of the above is it’s easier to make a mistake like:
if (x == 2); // notice the semicolon!
//do something
Nested If Statements / Cascading if statements
Switch
statements are better
switch (expression1)
{
case 1:
// do stuff here
break;
case 2:
// do other stuff
break;
default:
// do the default stuff.
break;
}
Ch7 Statement Repetition Using Loops
for (i = start; i <= end; i++)
{
// {0, 5} first argument and right-justify it in a field of five characters
// {1,20} second argument and right-justify in a field of twenty characters
buff = string.Format("{0, 5}{1, 20}", i, i*i);
lstOutput.Items.Add(buff);
}
for loops – ideally suited for counting operations
while loops are good for searching for a particular value in a set
bucket = 1;
for (int i = num; i > 1; i--)
{
bucket *= i;
}
Don’t need to do the last factorial as it multiplies by 1, so leave i > 1.
Keyboard shortcut – F7 to view designer / view code
Notice the currency here:
buff = string.Format("{0,4}, {1,15:C}", i, assetIsWorth);
lblResults.Items.Add(buff);
http://www.programgood.net/2009/12/14/ParameterPassingInCValueAndReferenceTypes.aspx