Head First C#
What will you learn from this book?
Head First C# is a complete learning experience for programming with C#, the .NET Framework, and the Visual Studio IDE. Built for your brain, this book covers C# and .NET 4.0 and Visual Studio 2010, and teaches everything from inheritance to serialization. You'll query your data with LINQ, draw graphics and animation, and learn all about classes and object oriented programming, all through building games, doing hands-on projects, and solving puzzles. You'll become a solid C# programmer, and you'll have a great time along the way!
Every few chapters you will come across a lab that lets you apply what you've learned up to that point. Each lab is designed to simulate a professional programming task, increasing in complexity until-at last-you build a working Invaders game, complete with shooting ships, aliens descending while firing, and an animated death sequence for unlucky starfighters. This remarkably engaging book will have you going from zero to 60 with C# in no time flat.
What you need for this book
We wrote this book using Visual Studio 2010, which uses C# and .NET Framework 4.0. All of the screenshots that you see throughout the book were taken from that edition, so we recommend that you use it. If you're using Visual Studio 2008 Professional, Ultimate, or Premium editions, you'll see some small differences, which we've pointed out wherever possible. You can download Visual Studio 2010 for free from Microsoft's website—it installs cleanly alongside other editions, as well as previous versions of Visual Studio.
Code Viewing and Downloads
The following code samples are from the second edition. For your convenience, you can also download all of the first edition code samples (zip).
- (Chapter 1 code is coming soon)
- Chapter 2, Familiar Math Symbols, Time to Start Coding, Code Magnets and Pool Puzzle, Fun with If Else, and Flashy Thing
- Chapter 3, Talker Tester, Clowns, Pool Puzzle, Joe and Bob, and Joe and Bob Part 2
- Chapter 4, Mileage Calculator, Swapping Elephants, Sloppy Joe, Biggest Ears, Code Magnets, Pool Puzzle, and Hit the Keys
- Chapter 5, Party Planner Part 1, Cow Calculator, CableBill, Party Planner Part 2
- Chapter 6, Party Planner Part 2, Mixed Messages, Pool Puzzle, JewelThief, MyBaseClass, Party Planner Part 2 with Inheritance, Bee Management System Part 1, and Bee Management System Part 2
- Chapter 7, Implement the IStingPatrol Interface, TallGuy, Fingers the Clown, PlanetMission, Let's Build a House, and Hide and Seek
- Chapter 8, Playing Card, Shoe Closet, Code Magnets, List of Ducks, Sort of Random Cards, Upcast an Entire List, Build Your Own Overloaded Methods, Two Decks, Dictionary in Action, Retired Jersey Numbers, Go Fish (without solution code), Go Fish, Queue and Stack, and Breakfast for Lumberjacks
- Chapter 9, The Swindler Launches Another Diabolical Plan, StreamWriter Magnets, Reading and Writing Using Two Objects, Pool Puzzle, Simple Text Editor, Excuse Manager, Body Parts, Serializable Guy, Serialize a Deck of Cards, Eureka, Use a BinaryWriter , HexDumper Using StreamReader, HexDumper, Excuse Manager (Serializable)
- Chapter 10, Pool Puzzle, Exception Magnets, and Excuse Manager (Serializable)
- Chapter 11, Baseball, Forms Use Events, ConvertsIntToString Delegate, Secret Ingredients, Pool Puzzle, Baseball (with callbacks), and Whack-a-mole
- Chapter 12, Beehive Simulator
- Chapter 13, BeeControl (Picturebox), BeeControl (UserControl), Beehive Simulator (UserControls), Image Resizing, A 30-Second Tour of GDI+ Graphics, Nectar Here, Sharpen Your Pencil 1, Sharpen Your Pencil 2, Drawing Bees, Zoomer, Beehive Simulator (Graphics), Print a Bee, Beehive Simulator (Printing)
- Chapter 14, Disposing Clones, Disposing Clones (with serialization), A Struct Called Dog, Using Out and Optional Parameters, Robust Guy, Pool Puzzle, Ordinary Human, Extending String, and Extension Magnets
- Chapter 15, LINQ Makes Queries Easy, Jimmy's Commics, LINQ is Versatile, LINQ Magnets, Pool Puzzle, LINQ to SQL, and Starbuzz
- (Appendix code is coming soon)
Get the graphics files (all zip downloads):
- Chapter 1, Objectville Paper Company logo
- Chapter 13, Bee Simulation graphics
- Lab #1, A Day at the Races graphics
- Lab #2, The Quest graphics
- Lab #3, Invaders graphics
Check out the labs:We made you write the code, and you sent us some great ones! Congratulations to everyone who participated. You can still send in creative alternatives, though—see these details.
- Lab #1, A Day at the Races: Here's the working program, submitted by Brandon Copeland from Houston, TX.
- Lab #2, The Quest: Here's the working program, submitted by Neil Hughes from Wirral, England.
- Lab #3, Invaders: Here's the working program, submitted by Ray Folwell from Derby, UK.
"For computer programmers who do not have a solid understanding of object-oriented programming (OOP), learning the C# programming language can be rather challenging, even if they have experience with C or C++, which at least would give them a head start over non-C programmers. Any developer in this situation may well want to begin the learning process with a book that aims to teach both OOP and C# in as gentle a manner as possible, with plenty of patient explanations and illustrative diagrams—such as those found in the book Head First C# by Andrew Stellman and Jennifer Greene."
—Michael J. Ross, Slashdot
"Head First C# is absolutely the best introduction to the C# language for C# beginners...I have already expressed myself elsewhere on the Head First Series and my enthusiasm remains strong. And, I would like to remind the reader not to skip around in the text; rather, they should work methodically through the various steps and sections in order to benefit from this structured teaching style. Trust the authors; and, let the book work its magic on you. (What? No "Hello, World!" program?!)"
—Will Wagers, C# Online
"I've never read a computer book cover to cover, but this one held my interest from the first page to the last. If you want to learn C# in depth and have fun doing it, this is THE book for you."
—Andy Parker, fledgling C# programmer
"Head First C# is a great book for hobbyist programmers. It provides examples and guidance on a majority of the things [those] programmers are likely to encounter writing applications in C#."
—Peter Ritchie, Microsoft MVP (2006-2007), Visual Developer, C#
"With Head First C#, Andrew and Jenny have presented an excellent tutorial on learning C#. It is very approachable while covering a great amount of detail in a unique style. If you've been turned off by more conventional books on C#, you'll love this one."
—Jay Hilyard, Software Developer, co-author of C# 3.0 Cookbook
"Head First C# is perfect blend of unique and interesting ways covering most of the concepts of programming. Fun excercises, bullet points, and even comic strips are some of the catchy and awesome works that this book has. The game-based labs are something that you really don't want to miss. [This book is] a great work... the novice as [well as the] well-experienced will love this book. GREAT JOB!"
—Aayam Singh, .NET professional
"Head First C# is a highly enjoyable tutorial, full of memorable examples and entertaining exercises. Its lively style is sure to captivate readers—from the humorously annotated examples, to the Fireside Chats, where the abstract class and interface butt heads in a heated argument! For anyone new to programming, there's no better way to dive in."
—Joseph Albahari, C# Design Architect at Egton Medical Information Systems, the UK's largest primary healthcare software supplier, co-author of C# 3.0 in a Nutshell
"[Head First C#] was an easy book to read and understand. I will recommend this book to any developer wanting to jump into the C# waters. I will recommend it to the advanced developer that wants to understand better what is happening with their code. [I will recommend it to developers who] want to find a better way to explain how C# works to their less-seasoned developer friends."
—Giuseppe Turitto, C# and ASP.NET developer for Cornwall Consulting Group
"Andrew and Jenny have crafted another stimulating Head First learning experience. Grab a pencil, a computer, and enjoy the ride as you engage your left brain, right brain, and funny bone."
—Bill Mietelski, Software Engineer
"Going through this Head First C# book was a great experience. I have not come across a book series which actually teaches you so wellÖThis is a book I would definitely recommend to people wanting to learn C#"
—Krishna Pala, MCP
(opens a new window)
(opens a new window)
Buy 2 books and get the third free! Use the coupon code OPC10 when you check out.
Due to a production issue, the following text was cut off of page 162:
Before you go on, there are three properties you need to set. Set the Timer controlís Enabled property to True, the ProgressBar controlís Maximum property to 701, and the Formís KeyPreview property to True.
Without these properties set, the typing game won't run, and you won't have everything you need to do the lab. Please download this correction to keep with your book. We're really sorry about any frustration this caused!
If you can answer "yes" to all of these:
- Do you want to learn C#?
- Do you like to tinker—do you learn by doing, rather than just reading?
- Do you prefer stimulating dinner party conversation to dry, dull, academic lectures?
You should probably back away from this book if you can answer "yes" to any of these:
- Does the idea of writing a lot of code make you bored and a little twitchy?
- Are you a kick-butt C++ or Java programmer looking for a reference book?
- Are you afraid to try something different? Would you rather have a root canal than mix stripes with plaid? Do you believe that a technical book can't be serious if C# concepts are anthropomorphized?
Ask the authors questions and chat with fellow readers in the Head First C# Forum.
Head First PMP offers 100% coverage of The PMBOK® Guide principles and certification objectives in a way that's engaging, not tedious.
What makes software projects succeed? It takes more than a good idea and a team of talented programmers. Applied Software Project Management provides you with tools, techniques, and practices that you can use on your own projects right away.