Rod Stephens
C# 24-Hour Trainer
Introduction
So you want to learn C# programming? Excellent choice!
C# is a powerful, general-purpose programming language that lets you build desktop, Windows Store, Windows Phone, and web apps. C# provides all of the tools that you need to build a huge variety of applications such as:
● Database applications
● Point of sales systems
● Two- and three-dimensional graphics programs
● Image-processing and photo-manipulation systems
● Computer-aided design (CAD) systems
● Document layout and printing systems
● Hardware control systems
● High-performance games
● Much, much more
NOTE
In case you ever need to mention it at parties, C# is pronounced “see sharp.” It's written C# because the number sign (#) is the closest most keyboards can get to the musical sharp symbol
.Of course, you won't be able to solve every problem with C#. If you want a program that picks the winning number on a roulette wheel or that can predict stock prices, you may have better luck using tarot cards (or a degree in economics), but for tractable problems C# is a great choice.
This book is a self-paced guide to C# programming in the Visual Studio environment. It uses easy-to-follow lessons, reinforced by step-by-step instructions, screencasts, and supplemental exercises, to help you master C# programming quickly and painlessly. It explains how to write C# programs that interact with the user to read inputs, calculate results, and display outputs. It shows how to read and write files, make printouts, and use databases. It shows how to build programs that run on the Windows desktop, on tablet computers, and on Windows Phones.
This book won't make you an expert, but it will give you a solid understanding of how to write C# programs. When you've finished reading this book and working through the Try It sections and exercises, you'll be able to write non-trivial programs of your own. You may not be able to accurately pick winning lottery numbers (if you do, please let me know!), but you will be able to build some useful programs and you'll be ready to learn more about more specialized topics that interest you such as database programming, file processing, and graphics.
What's New in the Second Edition
This second edition has been modified and expanded to provide more material than the first edition, but it's not intended to be the second in a series. If you read the first edition, don't get the second edition because there's a lot of overlap.
The main differences between this edition and the first are:
● More exercises (almost 400!)
● More screencast videos (more than 12 hours!)
● Windows Store apps
● Windows Phone apps
● A lot more material about Windows Presentation Foundation (WPF) and eXtensible Markup Language (XAML) (which you can use to build Windows Store and Windows Phone style apps)
To make room for the new material, some of the old material had to go. This edition doesn't cover:
● The clipboard and drag-and-drop
● Bitmap manipulation
● Parallel programming
● Console applications
I'd love to include those topics and many others, but there just isn't room in a book of this size.
Who This Book Is For
This book is for anyone who wants to learn how to write programs using C#. Whether you want to move into a lucrative career as a software developer, add a few new skills to your résumé, or pick up a fascinating new hobby, this book can get you started.
This book does not assume you have any previous programming experience. It assumes you're uninformed rather than an idiot or a dummy. It assumes you can turn your computer on and surf the web but that's about it for previous qualifications. It is suitable as a first programming book for high school or college students, but its self-paced hands-on approach also makes it ideal if you're trying to learn to program on your own.
(I don't want to receive a bunch of flaming e-mails complaining that the material in this book is too basic, so I'm warning you right now. If you've been programming in C++ or Visual Basic for 16 years, don't blame me if a lot of this material seems pretty simple to you. Instead of wasting your time complaining, go find a more advanced book.)
What This Book Covers (And What It Doesn't)
This book explains C# programming. It explains how to write, debug, and run applications that interact with the user and the computer. It shows how to understand object-oriented concepts, perform calculations, manipulate files and strings, produce printouts, and interact with simple databases. It explains how to run programs on your desktop, from the Windows Start menu, with a Windows tablet-style interface, and on a Windows Phone.
Programming in any language is an enormous topic, however, so this book doesn't cover everything. It doesn't explain how to design databases, build cryptographically secure web applications, create multithreaded programs that run on multiple CPUs, or build Xbox games, all tasks that are possible using C#. When you're finished reading this book, however, you'll be ready to move on to more advanced books that cover those topics.
The Wrox 24-Hour Trainer Approach
Educators have known for many years that different people use different learning styles most effectively. Different students may learn best by:
● Reading a textbook
● Looking at nonwritten material such as pictures and graphs
● Listening to an instructor lecture
● Watching someone demonstrate techniques
● Doing exercises and examples
(Personally, I learn best by watching and doing.)
Good instructors try to incorporate material that helps students with all of these learning styles. Combining text, lecture, demonstration, discussion, and exercises lets every student pick up as much as possible using whichever methods work best.
Like a good instructor, this book uses materials that address each learning style. It uses text and figures to help visual learners, screencasts that provide visual demonstrations and auditory instruction, step-by-step instructions to help you do it yourself, and exercises for further study.
The book is divided into small, bite-sized lessons that begin with a discussion of a particular concept or technique, complete with figures, notes, tips, and other standard fare for instructional books. The lessons are short and tightly focused on a single task so you can finish each one in a single sitting. You shouldn't need to stop in the middle of a lesson and leave concepts half-learned (at least if you turn off your phone).
NOTE
The “24-Hour” in the title means the book is available to train you 24 hours per day, not that you should be able to read then entire book in 24 hours. Unless you just skim the text and skip all of the Try Its and exercises, I'd be surprised if anyone could work through the whole thing in 24 hours.
After describing the main concept, the lesson includes a Try It section that invites you to perform a programming exercise to solidify the lesson's ideas.
The Try It has several subsections. Lesson Requirements describes the exercise so you know what should happen. Hints gives pointers about possible confusing aspects of the problem, if they're needed. Step-by-Step provides a numbered series of steps that show how to