2010 - Head First C# 2e (O'Reilly).pdf

(23229 KB) Pobierz
568141866 UNPDF
Head First C#
Second Edition
Wouldn’t it be dreamy
if there was a C# book that
was more fun than endlessly
debugging code? It’s probably
nothing but a fantasy....
Andrew Stellman
Jennifer Greene
Beijing • Cambridge • Kln • Sebastopol • Taipei • Tokyo
568141866.003.png 568141866.004.png 568141866.005.png
Head First C#
Second Edition
by Andrew Stellman and Jennifer Greene
Copyright © 2010 Andrew Stellman and Jennifer Greene. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly Media books may be purchased for educational, business, or sales promotional use. Online editions are also
available for most titles ( http://my.safaribooksonline.com ). For more information, contact our corporate/institutional sales
department: (800) 998-9938 or corporate@oreilly.com .
Series Creators: Kathy Sierra, Bert Bates
Cover Designers: Louise Barr, Karen Montgomery
Production Editor: Rachel Monaghan
Proofreader: Emily Quill
Indexer: Lucie Haskins
Page Viewers: Quentin the whippet and Tequila the pomeranian
Printing History:
November 2007: First Edition.
May 2010: Second Edition.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. The Head First series designations, Head First C# ,
and related trade dress are trademarks of O’Reilly Media, Inc.
Microsoft, Windows, Visual Studio, MSDN, the .NET logo, Visual Basic and Visual C# are registered trademarks of
Microsoft Corporation.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks.
Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the
designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and the authors assume no
responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
No bees, space aliens, or comic book heroes were harmed in the making of this book.
ISBN: 978-1-449-38034-2
[SB]
568141866.006.png
This book is dedicated to the loving memory of Sludgie the Whale,
who swam to Brooklyn on April 17, 2007.
You were only in our canal for a day,
but you’ll be in our hearts forever.
568141866.001.png
the authors
Thanks for buying our book! We really
love writing about this stuff, and we
hope you get a kick out of reading it…
…because we know
you’re going to have a
great time learning C#.
A ndrew
T his pho to (and the ph oto of the
Andrew Stellman , despite being raised a
New Yorker, has lived in Pittsburgh twice . The
first time was when he graduated from Carnegie
Mellon’s School of Computer Science, and then
again when he and Jenny were starting their
consulting business and writing their first book for
O’Reilly.
Jennifer Greene studied philosophy in
college but, like everyone else in the field, couldn’t
find a job doing it. Luckily, she’s a great software
engineer, so she started out working at an online
service, and that’s the first time she really got a
good sense of what good software development
looked like.
When he moved back to his hometown, his first
job after college was as a programmer at EMI-
Capitol Records—which actually made sense,
since he went to LaGuardia High School of
Music and Art and the Performing Arts to study
cello and jazz bass guitar. He and Jenny first
worked together at that same financial software
company, where he was managing a team of
programmers. He’s had the privilege of working
with some pretty amazing programmers over the
years, and likes to think that he’s learned a few
things from them.
She moved to New York in 1998 to work on
software quallity at a financial software company.
She managed a team of testers at a really cool
startup that did artificial intelligence and natural
language processing.
Since then, she’s traveled all over the world to work
with different software teams and build all kinds of
cool projects.
When he’s not writing books, Andrew keeps
himself busy writing useless (but fun) software,
playing music (but video games even more),
experimenting with circuits that make odd noises,
studying taiji and aikido, having a girlfriend
named Lisa, and owning a pomeranian.
She loves traveling, watching Bollywood movies,
reading the occasional comic book, playing PS3
games (especially LittleBigPlanet!), and owning a
whippet.
Jenny a nd Andrew have been building so ftware and writing a bout softw are engine ering toget her since they
first me t in 1998. Their fir st book, A pplied Sof tware Pro ject Mana gement , wa s published by O’Reilly in
2005. They publi shed their first book in the Hea d First se ries, Head First PM P , in 2007 .
They fo unded Ste llman & Gr eene Consu lting in 20 03 to buil d a really neat softw are projec t for
scientist s studying herbicide exposure in Vietnam vets. When they’re no t building software o r writing
books, t hey do a l ot of spea king at con ferences a nd meeting s of softw are engine ers, archit ects and
project managers.
Check o ut their b log, Buildin g Bette r Softwa re : http: //www.st ellman-g reene.com
viii
Gowanus Canal) by Nish a Sond he
568141866.002.png
table of contents
Table of Contents (Summary)
Intro
xxix
1 Get productive with C#: Visual Applications, in 10 minutes or less
1
2
It’s All Just Code: Under the hood
41
3 Objects: Get Oriented: Making code make sense
85
4 Types and References: It’s 10:00. Do you know where your data is?
125
C# Lab 1: A Day at the races
169
5 Encapsulation: Keep your privates… private
179
6
Inheritance: Your object’s family tree
215
7
Interfaces and abstract classes: Making classes keep their promises
269
8 Enums and collections: Storing lots of data
327
C# Lab 2: The Quest
385
9 Reading and Writing Files: Save the byte array, save the world
407
10 Exception Handling: Putting out fires gets old
463
11 Events and Delegates: What your code does when you’re not looking
507
12 Review and Preview: Knowledge, power, and building cool stuff
541
13 Controls and Graphics: Make it pretty
589
14 Captain Amazing: The Death of the Object
647
15 LINQ: Get control of your data
685
C# Lab 3: Invaders
713
i Leftovers: The top 11 things we wanted to include in this book
735
Table of Contents (the real thing)
Intro
Your brain on C#. You’re sitting around trying to learn something, but
your brain keeps telling you all that learning isn’t important . Your brain’s saying,
“Better leave room for more important things, like which wild animals to avoid and
whether nude archery is a bad idea.” So how do you trick your brain into thinking
that your life really depends on learning C#?
Who is this book for?
xxx
We know what you’re thinking
xxxi
Metacognition
xxxiii
Bend your brain into submission
xxxv
What you need for this book
xxxvi
Read me
xxxvii
The technical review team
xxxviii
Acknowledgments
xxxix
ix
Zgłoś jeśli naruszono regulamin