C# 5.0
IN A NUTSHELL
Fifth Edition
Joseph Albahari and Ben Albahari
Beijing
•
Cambridge
•
Farnham
•
Köln
•
Sebastopol
•
Tokyo
C# 5.0 in a Nutshell, Fifth Edition
by Joseph Albahari and Ben Albahari
Copyright © 2012 Joseph Albahari and Ben Albahari. 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 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 infor-
mation, contact our corporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editor: Rachel Roumeliotis
Production Editor: Melanie Yarbrough
Copyeditor: Nancy Reinhardt
Proofreader: Jennifer Knight
Indexer: Jay Marchand
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Robert Romano
June 2012: Fifth Edition.
Revision History for the Fifth Edition:
2012-06-08 First release
See
http://oreilly.com/catalog/errata.csp?isbn=9781449320102 for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trade-
marks of
O’Reilly Media, Inc. C# 5.0 in a Nutshell, the cover image of a numidian crane, and
related trade dress are trademarks of O’Reilly Media, Inc.
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
authors assume no responsibility for errors or omissions, or for damages resulting from the
use of the information contained herein.
ISBN: 978-1-449-32010-2
[M]
1340210346
Table of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1. Introducing C# and the .NET Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Object Orientation 1
Type Safety 2
Memory Management 2
Platform Support 3
C#’s Relationship with the CLR 3
The CLR and .NET Framework 3
C# and Windows Runtime 5
What’s New in C# 5.0 6
What’s New in C# 4.0 6
What’s New in C# 3.0 7
2. C# Language Basics . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
A First C# Program 9
Syntax 12
Type Basics 15
Numeric Types 23
Boolean Type and Operators 30
Strings and Characters 32
Arrays 34
Variables and Parameters 38
Expressions and Operators 47
Statements 51
Namespaces 59
iii
- 1
- 2
- 3
前往页