Академический Документы
Профессиональный Документы
Культура Документы
Approach
This tutorial follows an "objects first" approach. Windows applications are developed from scratch.
Concepts such as objects, classes, properties, events, methods are introduced prior to variables, types,
operators, operands and assignments. Programming for the console window and control structures such
as selection and iteration are introduced even later. This is done in the belief that students learn better if
they are allowed to discover rather than being taught.
Furthermore, this tutorial follows a minimalistic approach. Students should take every small bit of
information as very important as not-so-important material has simply not been included in the text.
Students and lecturers are advised to consult other texts as well.
This is a tutorial and not a text book. This means that students are expected to learn by doing. Instead
of reading through a text book, students are expected to sit in front of a computer and enter the
examples as given. Students should do all of the exercises at the end of every chapter. The exercises
were carefully selected to be representative of essential learning material. They do not only serve as
revision or assessment of existing knowledge but also as medium through which new knowledge should
be discovered. If you miss out on an exercise, you might miss out on some important learning material.
You will not become a good tennis player by watching Wimbledon on TV – you have to go out there and
hit the ball.
Every topic starts with a short introduction followed by a hands-on do-it-yourself section. A topic is
concluded with an Understand what you are doing section where important concepts are discussed and
explained with reference to the example. Concepts are bulleted on two levels to enable students to focus
on a specific concept at a time.
The key learning outcomes are listed at the beginning of every chapter and every chapter is concluded
with a section that lists some keywords that was discussed in the chapter as well as a set of exercises.
Concepts : Normal
Files and folders : Normal between quotes, e.g. "frmLogin.cs".
Classes and Controls : Green, e.g. Color, TextBox
Properties : Bold, e.g. List
Property values : As it appears in code, e.g. "John", 10, CenterScreen.
Methods : Bold with brackets, e.g. Remove()
Events : Bold with the word "event", e.g. DataError event
Event handlers : As for methods, e.g. Click().
Reserved words : Blue, e.g. new
It is important that the formulations with regard to objects and classes are understood correctly. For
example, "a TextBox object" refers to an object or specific instance of the TextBox class. Reference to
methods can refer to either static or non-static methods, unless specifically indicated.
Table of Contents
Part 1
1. Controls and Code
2. Drawing Figures
3. Handling Data
4. Console Applications
5. Structure of a C# program
6. Taking Decisions
9. Repeating things
Part 2
11. Class development
Appendices
A. Naming conventions
B. Glossary
ii
Comments 1-16
Resources 1-19
Keywords 1-19
Exercises 1-20
Keywords 2-6
Exercises 2-6
iii
Keywords 3-16
Exercises 3-17
Keywords 4-6
Exercises 4-6
iv
Namespaces 5-4
Keywords 5-7
Exercise 5-7
Errors 7-2
Debugging 7-4
Defensive programming 7-5
Keywords 7-9
Exercises 7-9
Recursion 9-26
Keywords 9-28
Exercises 9-29
vii
Arrays 10-18
Array basics 10-18
Declaration, instantiation, initialisation, traversing and sorting 10-18
A Windows Forms example 10-20
- Scope of an array, Entering data, Listing elements 10-20
- Add an additional element 10-23
- Remove an element 10-23
- Remove duplicates 10-24
- Insert an element into the middle of an array 10-24
- The smallest / largest element in an array 10-25
- The average of numbers in an array 10-26
Introduction 13-2
File management 13-2
OpenFileDialog 13-2
File attributes 13-3
File dates 13-3
Delete a file 13-4
Copy a file 13-4
List files in a directory 13-5
Text files 13-6
Saving to and reading from a text file 13-6
Allow the user to select a file and check that it exists 13-9
Binary files 13-11
Save to a binary file 13-11
Read from a binary file 13-13
Save an object to a binary file 13-14
Read an object from a binary file 13-15
Save an array of objects to a binary file 13-16
Read an array of objects from a binary file 13-18
Keywords 13-19
Exercises 13-20
x
Appendix B: Glossary
Hardware B-2
Software B-7