ebook img

C# 4.0 Pocket Reference PDF

218 Pages·2010·1.137 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview C# 4.0 Pocket Reference

C# 4.0 Pocket Reference THIRD EDITION C# 4.0 Pocket Reference Joseph Albahari and Ben Albahari Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo C# 4.0 Pocket Reference, Third Edition by Joseph Albahari and Ben Albahari Copyright © 2010 Joseph Albahari and Ben Albahari. All rights reserved. Printed in Canada. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Se- bastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promo- tional use. Online editions are also available for most titles (http://my.safari booksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or [email protected]. Editor: Mike Hendrickson Production Editor: Kristen Borg Proofreader: Kiel Van Horn Indexer: Angela Howard Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Printing History: November 2002: First Edition. February 2008: Second Edition. August 2010: Third Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. C# 4.0 Pocket Reference, the image of an African crowned 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-39401-1 [TM] 1280502296 Contents C# 4.0 Pocket Reference 1 Using Code Examples 2 How to Contact Us 2 Safari® Books Online 3 A First C# Program 3 Compilation 6 Syntax 7 Identifiers and Keywords 7 Literals, Punctuators, and Operators 9 Comments 10 Type Basics 10 Predefined Type Examples 10 Custom Type Examples 11 Conversions 14 Value Types Versus Reference Types 15 Predefined Type Taxonomy 18 Numeric Types 19 Numeric Literals 20 Numeric Conversions 21 Arithmetic Operators 22 Increment and Decrement Operators 22 Specialized Integral Operations 22 v 8- and 16-Bit Integrals 24 Special Float and Double Values 24 double Versus decimal 25 Real Number Rounding Errors 25 Boolean Type and Operators 26 Equality and Comparison Operators 26 Conditional Operators 27 Strings and Characters 28 String Type 29 Arrays 31 Default Element Initialization 32 Multidimensional Arrays 33 Simplified Array Initialization Expressions 34 Variables and Parameters 35 The Stack and the Heap 35 Definite Assignment 36 Default Values 37 Parameters 37 var—Implicitly Typed Local Variables 42 Expressions and Operators 43 Assignment Expressions 43 Operator Precedence and Associativity 44 Operator Table 45 Statements 48 Declaration Statements 48 Expression Statements 48 Selection Statements 49 Iteration Statements 52 Jump Statements 54 Namespaces 55 The using Directive 57 Rules Within a Namespace 57 vi | Table of Contents Aliasing Types and Namespaces 59 Classes 59 Fields 59 Methods 60 Instance Constructors 61 Object Initializers 62 The this Reference 63 Properties 63 Indexers 65 Constants 66 Static Constructors 67 Static Classes 68 Finalizers 68 Partial Types and Methods 68 Inheritance 70 Polymorphism 71 Casting and Reference Conversions 71 Virtual Function Members 73 Abstract Classes and Abstract Members 74 Hiding Inherited Members 74 Sealing Functions and Classes 75 The base Keyword 75 Constructors and Inheritance 76 Overloading and Resolution 77 The object Type 78 Boxing and Unboxing 79 Static and Runtime Type Checking 80 The GetType Method and typeof Operator 80 Object Member Listing 81 Equals, ReferenceEquals, and GetHashCode 81 The ToString Method 82 Structs 82 Table of Contents | vii Struct Construction Semantics 83 Access Modifiers 83 Friend Assemblies 84 Accessibility Capping 84 Interfaces 85 Extending an Interface 86 Explicit Interface Implementation 86 Implementing Interface Members Virtually 87 Reimplementing an Interface in a Subclass 87 Enums 88 Enum Conversions 89 Flags Enums 90 Enum Operators 91 Nested Types 91 Generics 92 Generic Types 92 Generic Methods 93 Declaring Type Parameters 94 typeof and Unbound Generic Types 95 The default Generic Value 95 Generic Constraints 95 Subclassing Generic Types 97 Self-Referencing Generic Declarations 97 Static Data 97 Covariance (C# 4.0) 98 Contravariance (C# 4.0) 99 Delegates 100 Writing Plug-in Methods with Delegates 101 Multicast Delegates 102 Instance Versus Static Method Targets 103 Generic Delegate Types 103 The Func and Action Delegates 103 viii | Table of Contents

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.