Home > Store > Programming > C#

Microsoft Visual C# Step by Step, 8th Edition

Register your product to gain access to bonus material or receive a coupon.

Microsoft Visual C# Step by Step, 8th Edition

Best Value Purchase

Book + eBook Bundle

  • Your Price: $59.39
  • List Price: $98.98
  • Includes EPUB, MOBI, and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    MOBI MOBI The eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

More Purchase Options

Book

  • Your Price: $43.99
  • List Price: $54.99
  • Usually ships in 24 hours.

eBook (Watermarked)

  • Your Price: $35.19
  • List Price: $43.99
  • Includes EPUB, MOBI, and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    MOBI MOBI The eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

About

Features

  • The proven step-by-step, "learn by doing" introduction to Visual C#: popular with programmers worldwide, and now fully up-to-date
  • Walks through building modern Windows applications that are both highly responsive and scalable
  • Includes exercises and sample projects throughout, with "before" and "after" downloadable code
  • For both new Visual C# programmers and millions of developers upgrading from older versions

Description

  • Copyright 2016
  • Pages: 816
  • Edition: 8th
  • Book
  • ISBN-10: 1-5093-0104-6
  • ISBN-13: 978-1-5093-0104-1

Your hands-on guide to Microsoft Visual C# fundamentals with Visual Studio 2015
Expand your expertise--and teach yourself the fundamentals of programming with the latest version of Visual C# with Visual Studio 2015. If you are an experienced software developer, you’ll get all the guidance, exercises, and code you need to start building responsive, scalable Windows 10 and Universal Windows Platform applications with Visual C#.

Discover how to:

  • Quickly start creating Visual C# code and projects with Visual Studio 2015
  • Work with variables, operators, expressions, and methods
  • Control program flow with decision and iteration statements
  • Build more robust apps with error, exception, and resource management
  • Master the essentials of Visual C# object-oriented programming
  • Use enumerations, structures, generics, collections, indexers, and other advanced features
  • Create in-memory data queries with LINQ query expressions
  • Improve application throughput and response time with asynchronous methods
  • Decouple application logic and event handling
  • Streamline development with new app templates
  • Implement the Model-View-ViewModel (MVVM) pattern
  • Build Universal Windows Platform apps that smoothly adapt to PCs, tablets, and Windows phones
  • Integrate Microsoft Azure cloud databases and RESTful web services
About You
  • For software developers who are new to Visual C# or who are upgrading from older versions
  • Readers should have experience with at least one programming language
  • No prior Microsoft .NET or Visual Studio development experience required

Downloads

Downloads

Follow the instructions to download this book's companion files or practice files.

  1. Click the Download button below to start the download.
  2. If prompted, click Save.
  3. Locate the .zip file on your computer. Right-click the file, click Extract All, and then follow the instructions.
Download

Sample Content

Sample Pages

Download the sample content

Table of Contents

Introduction     xix
PART I: INTRODUCING MICROSOFT VISUAL C# AND MICROSOFT VISUAL STUDIO 2015      
Chapter 1: Welcome to C#     3

Beginning programming with the Visual Studio 2015 environment     3
Writing your first program     8
Using namespaces     14
Creating a graphical application     17
Examining the Universal Windows Platform app     26
Adding code to the graphical application     29
Summary     32
Quick Reference     32
Chapter 2: Working with variables, operators, and expressions     33
Understanding statements     33
Using identifiers     34
Identifying keywords     34
Using variables     36
Naming variables     36
Declaring variables     37
Working with primitive data types     37
Unassigned local variables     38
Displaying primitive data type values     38
Using arithmetic operators     45
Operators and types     45
Examining arithmetic operators     47
Controlling precedence     52
Using associativity to evaluate expressions     53
Associativity and the assignment operator     53
Incrementing and decrementing variables     54
Prefix and postfix     55
Declaring implicitly typed local variables     56
Summary     57
Quick Reference     58
Chapter 3: Writing methods and applying scope     59
Creating methods     59
Declaring a method     60
Returning data from a method     61
Using expression-bodied methods     62
Calling methods     63
Applying scope     66
Defining local scope     66
Defining class scope     67
Overloading methods     68
Writing methods     68
Using optional parameters and named arguments     77
Defining optional parameters     79
Passing named arguments     79
Resolving ambiguities with optional parameters and named arguments     80
Summary     85
Quick reference     86
Chapter 4: Using decision statements     87
Declaring Boolean variables     87
Using Boolean operators     88
Understanding equality and relational operators     88
Understanding conditional logical operators     89
Short circuiting     90
Summarizing operator precedence and associativity     90
Using if statements to make decisions     91
Understanding if statement syntax     91
Using blocks to group statements     93
Cascading if statements     94
Using switch statements     99
Understanding switch statement syntax     100
Following the switch statement rules     101
Summary     104
Quick reference     105
Chapter 5: Using compound assignment and iteration statements     107
Using compound assignment operators     107
Writing while statements     108
Writing for statements     114
Understanding for statement scope     115
Writing do statements     116
Summary     125
Quick reference     125
Chapter 6: Managing errors and exceptions     127
Coping with errors     127
Trying code and catching exceptions     128
Unhandled exceptions     129
Using multiple catch handlers     130
Catching multiple exceptions     131
Propagating exceptions     136
Using checked and unchecked integer arithmetic     138
Writing checked statements     139
Writing checked expressions     140
Throwing exceptions     143
Using a finally block     148
Summary     149
Quick reference     150
PART II: UNDERSTANDING THE C# OBJECT MODEL
Chapter 7: Creating and managing classes and objects     153

Understanding classification     153
The purpose of encapsulation     154
Defining and using a class     154
Controlling accessibility     156
Working with constructors     157
Overloading constructors     158
Understanding static methods and data     167
Creating a shared field     168
Creating a static field by using the const keyword     169
Understanding static classes     169
Static using statements     170
Anonymous classes     172
Summary     174
Quick reference     174
Chapter 8: Understanding values and references     177
Copying value type variables and classes     177
Understanding null values and nullable types     183
Using nullable types     185
Understanding the properties of nullable types     186
Using ref and out parameters     187
Creating ref parameters     188
Creating out parameters     188
How computer memory is organized     190
Using the stack and the heap     192
The System.Object class     193
Boxing     194
Unboxing     194
Casting data safely     196
The is operator     196
The as operator     197
Summary     199
Quick reference     199
Chapter 9: Creating value types with enumerations
and structures     201
Working with enumerations     201
Declaring an enumeration     202
Using an enumeration     202
Choosing enumeration literal values     203
Choosing an enumeration’s underlying type     204
Working with structures     206
Declaring a structure     208
Understanding differences between structures and classes     209
Declaring structure variables     210
Understanding structure initialization     211
Copying structure variables     215
Summary     219
Quick reference     219
Chapter 10: Using arrays     221
Declaring and creating an array     221
Declaring array variables     221
Creating an array instance     222
Populating and using an array     223
Creating an implicitly typed array     224
Accessing an individual array element     225
Iterating through an array     225
Passing arrays as parameters and return values for a method    227
Copying arrays     228
Using multidimensional arrays     230
Creating jagged arrays     231
Summary     241
Quick reference     242
Chapter 11: Understanding parameter arrays     243
Overloading—a recap     243
Using array arguments     244
Declaring a params array     245
Using params object[ ]     247
Using a params array     249
Comparing parameter arrays and optional parameters     252
Summary     254
Quick reference     254
Chapter 12: Working with inheritance     255
What is inheritance?     255
Using inheritance     256
The System.Object class revisited     258
Calling base-class constructors     258
Assigning classes     259
Declaring new methods     261
Declaring virtual methods     262
Declaring override methods     263
Understanding protected access     265
Understanding extension methods     271
Summary     275
Quick reference     276
Chapter 13: Creating interfaces and defining abstract classes     277
Understanding interfaces     277
Defining an interface     278
Implementing an interface     279
Referencing a class through its interface     280
Working with multiple interfaces     281
Explicitly implementing an interface     282
Interface restrictions     283
Defining and using interfaces     284
Abstract classes     293
Abstract methods     295
Sealed classes     295
Sealed methods     295
Implementing and using an abstract class     296
Summary     302
Quick reference     303
Chapter 14: Using garbage collection and resource management 305
The life and times of an object     305
Writing destructors     306
Why use the garbage collector?     308
How does the garbage collector work?     310
Recommendations     310
Resource management     311
Disposal methods     311
Exception-safe disposal     312
The using statement and the IDisposable interface     312
Calling the Dispose method from a destructor     314
Implementing exception-safe disposal     316
Summary     325
Quick reference     325
PART III: DEFINING EXTENSIBLE TYPES WITH C#
Chapter 15: Implementing properties to access fields     329

Implementing encapsulation by using methods     329
What are properties?     331
Using properties     333
Read-only properties     334
Write-only properties     334
Property accessibility     335
Understanding the property restrictions     336
Declaring interface properties     337
Replacing methods with properties     339
Generating automatic properties     343
Initializing objects by using properties     345
Summary     349
Quick reference     350
Chapter 16: Using indexers     353
What is an indexer?     353
An example that doesn’t use indexers     353
The same example using indexers     355
Understanding indexer accessors     357
Comparing indexers and arrays     358
Indexers in interfaces     360
Using indexers in a Windows application     361
Summary     367
Quick reference     368
Chapter 17: Introducing generics     369
The problem with the object type     369
The generics solution     373
Generics vs. generalized classes     375
Generics and constraints     375
Creating a generic class     376
The theory of binary trees     376
Building a binary tree class by using generics     379
Creating a generic method     389
Defining a generic method to build a binary tree     389
Variance and generic interfaces     391
Covariant interfaces     393
Contravariant interfaces     395
Summary     397
Quick reference     397
Chapter 18: Using collections     399
What are collection classes?     399
The List<T> collection class     401
The LinkedList<T> collection class     403
The Queue<T> collection class     404
The Stack<T> collection class     405
The Dictionary<TKey, TValue> collection class     407
The SortedList<TKey, TValue> collection class     408
The HashSet<T> collection class     409
Using collection initializers     411
The Find methods, predicates, and lambda expressions     411
The forms of lambda expressions     413
Comparing arrays and collections     415
Using collection classes to play cards     416
Summary     420
Quick reference     420
Chapter 19: Enumerating collections     423
Enumerating the elements in a collection     423
Manually implementing an enumerator     425
Implementing the IEnumerable interface     429
Implementing an enumerator by using an iterator     431
A simple iterator     432
Defining an enumerator for the Tree<TItem> class by using an iterator     434
Summary     436
Quick reference     437
Chapter 20: Decoupling application logic and handling events     439
Understanding delegates     440
Examples of delegates in the .NET Framework class library     441
The automated factory scenario     443
Implementing the factory control system without using delegates     443
Implementing the factory by using a delegate     444
Declaring and using delegates     447
Lambda expressions and delegates     455
Creating a method adapter     455
Enabling notifications by using events     456
Declaring an event     456
Subscribing to an event     457
Unsubscribing from an event     457
Raising an event     458
Understanding user interface events     458
Using events     460
Summary     466
Quick reference     466
Chapter 21: Querying in-memory data by using query expressions     469
What is LINQ?     469
Using LINQ in a C# application     470
Selecting data     472
Filtering data     474
Ordering, grouping, and aggregating data     475
Joining data     477
Using query operators     479
Querying data in Tree<TItem> objects     481
LINQ and deferred evaluation     487
Summary     491
Quick reference     491
Chapter 22: Operator overloading     493
Understanding operators     493
Operator constraints     494
Overloaded operators     494
Creating symmetric operators     496
Understanding compound assignment evaluation     498
Declaring increment and decrement operators     499
Comparing operators in structures and classes     500
Defining operator pairs     500
Implementing operators     501
Understanding conversion operators     508
Providing built-in conversions     508
Implementing user-defined conversion operators     509
Creating symmetric operators, revisited     510
Writing conversion operators     511
Summary     513
Quick reference     514
PART IV: BUILDING UNIVERSAL WINDOWS PLATFORM APPLICATIONS WITH C#      
Chapter 23: Improving throughput by using tasks     517

Why perform multitasking by using parallel processing?     517
The rise of the multicore processor     518
Implementing multitasking by using the Microsoft .NET Framework     519
Tasks, threads, and the ThreadPool     520
Creating, running, and controlling tasks     521
Using the Task class to implement parallelism     524
Abstracting tasks by using the Parallel class     536
When not to use the Parallel class     541
Canceling tasks and handling exceptions     543
The mechanics of cooperative cancellation     543
Using continuations with canceled and faulted tasks     556
Summary     557
Quick reference     557
Chapter 24: Improving response time by performing
asynchronous operations     559
Implementing asynchronous methods     560
Defining asynchronous methods: The problem     560
Defining asynchronous methods: The solution     564
Defining asynchronous methods that return values     569
Asynchronous method gotchas     570
Asynchronous methods and the Windows Runtime APIs     572
Using PLINQ to parallelize declarative data access     575
Using PLINQ to improve performance while iterating through a collection     576
Canceling a PLINQ query     580
Synchronizing concurrent access to data     581
Locking data     584
Synchronization primitives for coordinating tasks     584
Canceling synchronization     587
The concurrent collection classes     587
Using a concurrent collection and a lock to implement thread-safe data access     588
Summary     598
Quick reference     599
Chapter 25: Implementing the user interface for a Universal Windows Platform app     601
Features of a Universal Windows Platform app     602
Using the Blank App template to build a Universal Windows Platform app     605
Implementing a scalable user interface     607
Applying styles to a UI     638
Summary     649
Quick reference     649
Chapter 26: Displaying and searching for data in a Universal Windows Platform app     651
Implementing the Model-View-ViewModel pattern     651
Displaying data by using data binding     652
Modifying data by using data binding     659
Using data binding with a ComboBox control     663
Creating a ViewModel     665
Adding commands to a ViewModel     669
Searching for data using Cortana     680
Providing a vocal response to voice commands     692
Summary     695
Quick reference     696
Chapter 27: Accessing a remote database from a Universal Windows Platform app     697
Retrieving data from a database     698
Creating an entity model     703
Creating and using a REST web service     712
Inserting, updating, and deleting data through a REST web service     728
Reporting errors and updating the UI     738
Summary     746
Quick reference     747
Index     749

Updates

Errata

We've made every effort to ensure the accuracy of this book and its companion content. Any errors that have been confirmed since this book was published can be downloaded below.

Download the errata

Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership