C 6 0 Pocket Reference 1st Edition Joseph Albahari - The latest updated ebook is now available for download
C 6 0 Pocket Reference 1st Edition Joseph Albahari - The latest updated ebook is now available for download
https://ebookfinal.com/download/c-4-0-pocket-reference-pocket-
reference-o-reilly-3rd-edition-ben-albahari/
https://ebookfinal.com/download/c-8-0-in-a-nutshell-the-definitive-
reference-1st-edition-joseph-albahari/
https://ebookfinal.com/download/picmicro-microcontroller-pocket-
reference-1st-edition-predko/
https://ebookfinal.com/download/swift-pocket-reference-second-edition-
gray/
Java EE 6 Pocket Guide 1st Edition Arun Gupta
https://ebookfinal.com/download/java-ee-6-pocket-guide-1st-edition-
arun-gupta/
https://ebookfinal.com/download/perl-pocket-reference-5th-edition-
johan-vromans/
https://ebookfinal.com/download/javascript-pocket-reference-third-
edition-david-flanagan/
https://ebookfinal.com/download/mac-os-x-pocket-reference-1st-edition-
chuck-toporek/
https://ebookfinal.com/download/clinician-s-pocket-reference-9th-ed-
edition-haist/
C 6 0 Pocket Reference 1st Edition Joseph Albahari
Digital Instant Download
Author(s): Joseph Albahari, Ben Albahari
ISBN(s): 9781491927410, 1491927410
Edition: 1
File Details: PDF, 3.09 MB
Year: 2015
Language: english
C# 6.0
Pocket
Reference
INSTANT HELP
FOR C# 6.0
PROGRAMMERS
www.it-ebooks.info
C# 6.0
Pocket Reference
www.it-ebooks.info
C# 6.0 Pocket Reference
by Joseph Albahari and Ben Albahari
Copyright © 2016 Joseph Albahari, Ben Albahari. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebasto‐
pol, 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://safaribook
sonline.com). For more information, contact our corporate/institutional sales
department: 800-998-9938 or corporate@oreilly.com.
While the publisher and the authors have used good faith efforts to ensure
that the information and instructions contained in this work are accurate, the
publisher and the authors disclaim all responsibility for errors or omissions,
including without limitation responsibility for damages resulting from the use
of or reliance on this work. Use of the information and instructions contained
in this work is at your own risk. If any code samples or other technology this
work contains or describes is subject to open source licenses or the intellec‐
tual property rights of others, it is your responsibility to ensure that your use
thereof complies with such licenses and/or rights.
978-1-491-92741-0
[M]
www.it-ebooks.info
Table of Contents
iii
www.it-ebooks.info
The object Type 87
Structs 92
Access Modifiers 93
Interfaces 95
Enums 98
Nested Types 101
Generics 101
Delegates 110
Events 117
Lambda Expressions 123
Anonymous Methods 127
try Statements and Exceptions 128
Enumeration and Iterators 136
Nullable Types 142
Operator Overloading 147
Extension Methods 150
Anonymous Types 152
LINQ 153
Dynamic Binding 178
Attributes 187
Caller Info Attributes 191
Asynchronous Functions 192
Unsafe Code and Pointers 202
Preprocessor Directives 206
XML Documentation 208
Index 213
iv | Table of Contents
www.it-ebooks.info
C# 6.0 Pocket Reference
NOTE
The programs and code snippets in this book mirror those
in Chapters 2 through 4 of C# 6.0 in a Nutshell and are all
available as interactive samples in LINQPad. Working
through these samples in conjunction with the book accel‐
erates learning in that you can edit the samples and
instantly see the results without needing to set up projects
and solutions in Visual Studio.
To download the samples, go to http://bit.ly/linq‐
pad_csharp6_samples. LINQPad is free—go to www.linq‐
pad.net.
1
www.it-ebooks.info
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames,
and file extensions.
Constant width
Used for program listings, as well as within paragraphs to
refer to program elements such as variable or function
names, databases, data types, environment variables, state‐
ments, and keywords.
Constant width bold
Shows commands or other text that should be typed liter‐
ally by the user.
Constant width italic
Shows text that should be replaced with user-supplied val‐
ues or by values determined by context.
TIP
This element signifies a tip or suggestion.
NOTE
This element signifies a general note.
WARNING
This element indicates a warning or caution.
How to Contact Us
Please address comments and questions concerning this book
to the publisher:
We have a web page for this book, where we list errata, exam‐
ples, and any additional information. You can access this page
at http://bit.ly/csharp6_pocketref.
To comment or ask technical questions about this book, send
email to bookquestions@oreilly.com.
For more information about our books, courses, conferences,
and news, see our website at http://www.oreilly.com.
A First C# Program
Here is a program that multiplies 12 by 30, and prints the
result, 360, to the screen. The double forward slash indicates
that the remainder of a line is a comment.
using System; // Importing namespace
A First C# Program | 5
www.it-ebooks.info
using System;
class Test
{
static void Main()
{
Console.WriteLine (FeetToInches (30)); // 360
Console.WriteLine (FeetToInches (100)); // 1200
}
NOTE
An array (such as string[]) represents a fixed number of
elements of a particular type (see “Arrays” on page 34).
namespace TestPrograms
{
class Test {...}
class Test2 {...}
}
The using directive is there for convenience; you can also refer
to a type by its fully qualified name, which is the type name
prefixed with its namespace, such as System.Text.String
Builder.
A First C# Program | 7
www.it-ebooks.info
Compilation
The C# compiler compiles source code, specified as a set of files
with the .cs extension, into an assembly. An assembly is the unit
of packaging and deployment in .NET. An assembly can be
either an application or a library. A normal console or Win‐
dows application has a Main method and is an .exe file. A
library is a .dll and is equivalent to an .exe without an entry
point. Its purpose is to be called upon (referenced) by an appli‐
cation or by other libraries. The .NET Framework is a set of
libraries.
The name of the C# compiler is csc.exe. You can either use an
IDE such as Visual Studio to compile, or call csc manually
from the command line. To compile manually, first save a pro‐
gram to a file such as MyFirstProgram.cs, and then go to the
command line and invoke csc (located in %Program‐
Files(X86)%\msbuild\14.0\bin as follows:
csc MyFirstProgram.cs
WARNING
Peculiarly, .NET Framework 4.6 ships with the C# 5 com‐
piler. To obtain the C# 6 command-line compiler, you
must install Visual Studio or MSBuild 14.
class Test
{
static void Main()
{
int x = 12 * 30;
Console.WriteLine (x);
}
}
Most keywords are reserved, which means that you can’t use
them as identifiers. Here is the full list of C# reserved key‐
words:
Syntax | 9
www.it-ebooks.info
abstract enum long stackalloc
as event namespace static
base explicit new string
bool extern null struct
break false object switch
byte finally operator this
case fixed out throw
catch float override true
char for params try
checked foreach private typeof
class goto protected uint
const if public ulong
continue implicit readonly unchecked
decimal in ref unsafe
default int return ushort
delegate interface sbyte using
do internal sealed virtual
double is short void
else lock sizeof while
Avoiding conflicts
If you really want to use an identifier that clashes with a
reserved keyword, you can do so by qualifying it with the @ pre‐
fix. For instance:
class class {...} // Illegal
class @class {...} // Legal
Contextual keywords
Some keywords are contextual, meaning they can also be used
as identifiers—without an @ symbol. These are:
Comments
C# offers two different styles of source-code documentation:
single-line comments and multiline comments. A single-line
Syntax | 11
www.it-ebooks.info
comment begins with a double forward slash and continues
until the end of the line. For example:
int x = 3; // Comment about assigning 3 to x
Type Basics
A type defines the blueprint for a value. In our example, we
used two literals of type int with values 12 and 30. We also
declared a variable of type int whose name was x.
A variable denotes a storage location that can contain different
values over time. In contrast, a constant always represents the
same value (more on this later).
All values in C# are an instance of a specific type. The meaning
of a value, and the set of possible values a variable can have, is
determined by its type.
int x = 2015;
message = message + x.ToString();
Console.WriteLine (message); // Hello world2015
The predefined bool type has exactly two possible values: true
and false. The bool type is commonly used to conditionally
branch execution flow with an if statement. For example:
bool simpleVar = false;
if (simpleVar)
Console.WriteLine ("This will not print");
int x = 5000;
bool lessThanAMile = x < 5280;
if (lessThanAMile)
Console.WriteLine ("This will print");
NOTE
The System namespace in the .NET Framework contains
many important types that are not predefined by C# (e.g.,
DateTime).
Type Basics | 13
www.it-ebooks.info
ratio = unitRatio;
}
class Test
{
static void Main()
{
UnitConverter feetToInches = new UnitConverter(12);
UnitConverter milesToFeet = new UnitConverter(5280);
Members of a type
A type contains data members and function members. The data
member of UnitConverter is the field called ratio. The func‐
tion members of UnitConverter are the Convert method and
the UnitConverter’s constructor.
Ohria Kauroja
tynnyriä tynnyriä
Oulun lääniin 13,400 1,000
Kuopion " 15,650 700
Waasan " 15,200 7,000
Mikkelin " 6,700 850
Turun " 5,550 1,600
Hämeen " 5,700 1,000
Uudenmaan " 1,300 —
Wiipurin " 500 —
_____________________________________
Summa: 64,000 12,150
Missä hätä oli suurin, siellä apukin tuli runsain. Nuo kolme
pohjoista lääniä leikkasivat syksyllä 1868 erittäin runsaan sadon
kylvöstänsä. Etelämmällä tosin vaivasi kovat poudat, eikä sato,
semminkin omista heikommista siemenistä, ollut varsin kiitettävä.
Mutta eihän silloin oltu paljoon totuttukaan. Jos olivatkin hinkalot
puolillaan, niin oli tuo jo ilahuttava näky edelliseen tyhjyyteen
verraten.
Riihimäen—Pietarin rautatie.
Yksityisten ponnistukset.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com