Introduction

Over the past 30 years I've written 18 books on various programming topics. You might wonder, why so many…? Didn't I get it right the first time? Well, no, I didn't…not really. When I wrote my first book more than 30 years ago, object-oriented programming (OOP) was obscure at best and unknown to most. Like so many others, I had to go through the OOP learning process before I could appreciate what OOP was all about. I have a feeling that there are a lot of people out there who still feel that way.

Each time I teach a programming class, I learn new and better ways to explain things. When I look out across a classroom filled with students and it looks like a still-life painting, it's time to back off, retool, and try a different approach to whatever concept it is I'm trying to teach. Every class I've taught has offered new perspectives on how I teach and how students learn. I've had the opportunity to teach both in a university setting and on site at various companies both here and in Europe. Each experience presented different teaching challenges. Changing my examples and the techniques I use to teach programming concepts is one of the reasons I came back to teaching after so many years away…. I missed the learning experience.

A number of the books I wrote were concerned with languages other than C#, but that too provides for an enriching experience for me as an instructor. The strengths and weaknesses of a language can be appreciated only if you've grappled with some other less-than-perfect languages. The fact that programming languages continue to evolve supports the conclusion that I'm not the only one who is still learning. After all this time, the one thing that I have learned with absolute certainty is that whatever I know today will likely be out of date tomorrow.

Perhaps the question you should ask yourself is, “Why should I buy this book instead of someone else's book?” A number of factors come into play, but only one actually makes a difference: This book provides the techniques, examples, and approach to teaching the various programming concepts I've honed through working with literally thousands of students. I've learned what works and what doesn't. So many authors today are, no doubt, brilliant coders, but they haven't had to stumble through the bad examples and teaching methods that simply don't work. Writing good code does not necessarily equate to writing good books.

I think you will find this book informative, clear in its examples, and perhaps even entertaining in its narrative. I hope you'll give it a chance…. I think you'll enjoy the book. Even more important, however, is that you will come to appreciate all that object-oriented programming and C# can do for you.

Who This Book Is For

The book assumes no prior programming experience. That does not mean, however, that the book is “dumbed down” in any way. I build slowly, placing you on solid ground before the next topic is introduced. I encourage you to write your own programs and do the exercises at the end of each chapter. If you try to take shortcuts, you're actually shortchanging yourself. You should type in every line of code in this book and experiment with it. Do so and you will pick up the language twice as fast and with greater understanding than if you don't do the examples. (You can download the code from the Wrox website. Details are provided later.) You can learn programming only by writing programs and I encourage you to do so at every possible opportunity.

If you have some programming experience, that's fine, too. This book will likely be an easy read for you. However, you will learn some things along the way. If you have never programmed before…perfect! You don't have the bad programming baggage so many bring to the experience when they learn a new language.

This is the perfect book for someone who knows a programming language but learned that language before object-oriented programming techniques came into existence. There are a lot of “old-timers” like myself who would like to retrain themselves in OOP techniques and gain a full appreciation of what OOP brings to the table. This book suits that need perfectly.

Unlike other books, I don't recommend skipping chapters if you already know a programming language or have some other prior programming experience. If you're familiar with symbol tables, lvalues, and rvalues, and the Bucket Analogy, good—but it won't hurt you to read about them again from a different perspective. No shortcuts, remember.

What This Book Covers

This text begins with a nonprogramming-language introduction to object-oriented programming. The goal of that chapter is to present the concept of objects first and then ease into how objects may be viewed in C#. Virtually all of the concepts presented in this book are portable to other languages. The program design skills, coding style and techniques, and debugging methods are applicable to almost any programming language. C# and Visual Studio are simply the vehicle for teaching these skills.

Throughout the book common, easily understood examples introduce new programming concepts. Most of the C# programming language is covered; although, there are a few less-common topics not covered. These omissions aren't important to the task at hand, which is to teach you OOP using C#. When you have completed this book, you should feel comfortable designing, writing, testing, and debugging complex OOP programs of your own design.

How This Book Is Structured

The sequencing of the chapters was dictated by what I use when I taught this class to freshmen students. The chapter count is no accident and is geared to a college programming course of one semester in length. If you use the book as a self-study guide, great, but don't feel that you need to speed through the book. Understand each chapter before moving onto the next. Take the time to let things “sink in.”

The sequence makes logical sense, and each chapter builds upon the information contained in the previous chapters. Although you could skip around, this would detract from the learning experience. I have my own way to explain things and some are unusual…but they work.

Each chapter has several questions and exercises at the end of it. You are encouraged to work through those examples before you progress to the next chapter. As said previously, you can learn programming only by writing programs. It's easy to get lulled into a false sense of security by reading code and saying, “Yeah, I got that.” Perhaps…perhaps not. Writing your own programs is the only way to know for sure.

What You Need to Use This Book

All the examples in this book were written using Visual Studio 2012 and C#. As I write this material, C# Express is available only for Windows 8. However, Visual Studio Professional is available for other versions of Windows. Although Visual Studio Professional has a limited trial period, that time slice is more than long enough to work through this book. By the time you finish this book, you will likely want to purchase Visual Studio, anyway.

Instructions in Chapter 1, “Introducing C#,” tell you how to download and install VisualStudio Professional and C# from Microsoft at no charge. If you use Windows 8, you may want to download the Express version of Visual Studio. It is an incredible piece of software and has most of the functionality of the full Visual Studio. There are some nice tools missing from the Express edition, but there is enough there for you to experience most of what Visual Studio and C# have to offer.

You should use a Pentium-based system (although emulators also exist for the Mac and Linux, and they appear to work well) with at least 4G of memory and 11G of disk space. As mentioned, the version of Windows you use may affect which flavor of Visual Studio you want to download. The examples in this book work with either the Professional or Express versions of C#. After those requirements, the system you use is a matter of taste.

The source code for the samples is available for download from the Wrox website at:

Conventions

To help you get the most from the text and keep track of what's happening, this book uses a number of style conventions throughout the book. What follows is a list of the book's style conventions. (You will also see a number of programming conventions, which are introduced as needed throughout the text.)


Try It Out
The Try it Out is an exercise you should work through, following the text in the book.
1. They usually consist of a set of steps.
2. Each step has a number.
3. Follow the steps through with your copy of the code.
How it Works
After each Try It Out, the code you've typed will be explained in detail.


Note
Note, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

  • We italicize new terms and important words when we introduce them.
  • We show keyboard strokes like this: Ctrl+A.
  • We show filenames, URLs, and code within the text like so: persistence.properties.

Code snippets and listings are presented in this way:

We use a monofont type with no highlighting for most code examples.
Code snippets and listings are almost always more than one line long.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All the source code used in this book is available for download at www.wrox.com.

You can also search for the book at www.wrox.com by ISBN (the ISBN for this book is978-1-118-33692-2 to find the code. And a complete list of code downloads for all current Wrox books is available at www.wrox.com/dynamic/books/download.aspx.

At the beginning of each chapter, we've provided the folder name for the code in the chapter. Throughout each chapter, you can also find references to the names of the individual code files as needed in listing titles and text.

Most of the code on www.wrox.com is compressed in .ZIP, .RAR, or a similar archive format appropriate to the platform. After you download the code, just decompress it with an appropriate compression tool.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, noone is perfect, and mistakes do occur. If you find an error in one of our books, like a spellingmistake or faulty piece of code, we would be grateful for your feedback. By sending in errata you may save another reader hours of frustration, and at the same time you can help us provide even higher-quality information.

To find the errata page for this book, go to:

www.wrox.com/remtitle.cgi?isbn=1118336925and click the Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors.

If you don't spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at http://p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies and to interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums. I try to check the forum on a regular basis, visiting at least several times each week.

At http://p2p.wrox.com you can find a number of different forums that to help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to http://p2p.wrox.com and click the Register link.
2. Read the terms of use and click Agree.
3. Complete the required information to join, as well as any optional information you want to provide, and click Submit.
4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

Warning
You can read messages in the forums without joining P2P, but to post your own messages, you must join. After you join, you can post new messages and respond to messages other users post. You can read messages at any time on the web. If you want to have new messages from a particular forum e-mailed to you, click the Subscribe to This Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P forum, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questionsspecific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.210.104