Get Microsoft visual c# step by step 10th edition john sharp free all chapters

Page 1


https://ebookmass.com/product/microsoft-visual-c-step-by-

Instant digital products (PDF, ePub, MOBI) ready for you

Download now and discover formats that fit your needs...

Microsoft Visual C# Step by Step, 9th Edition John Sharp

https://ebookmass.com/product/microsoft-visual-c-step-by-step-9thedition-john-sharp/

ebookmass.com

Microsoft Project 2019 Step by Step (Step by Step (Microsoft)) Cindy Lewis & Carl Chatfield & Timothy Johnson [Lewis

https://ebookmass.com/product/microsoft-project-2019-step-by-stepstep-by-step-microsoft-cindy-lewis-carl-chatfield-timothy-johnsonlewis/

ebookmass.com

Elementary Statistics: A Step By Step Approach 10th Edition, (Ebook PDF)

https://ebookmass.com/product/elementary-statistics-a-step-by-stepapproach-10th-edition-ebook-pdf/

ebookmass.com

Islam, State, and Modernity: Mohammed Abed al-Jabri and the Future of the Arab World 1st Edition Zaid Eyadat

https://ebookmass.com/product/islam-state-and-modernity-mohammed-abedal-jabri-and-the-future-of-the-arab-world-1st-edition-zaid-eyadat/

ebookmass.com

Health systems science Second Edition. Edition Jeffrey M. Borkan (Editor)

https://ebookmass.com/product/health-systems-science-second-editionedition-jeffrey-m-borkan-editor/

ebookmass.com

Cultures of Diplomacy and Literary Writing in the Early Modern World Tracey A. Sowerby

https://ebookmass.com/product/cultures-of-diplomacy-and-literarywriting-in-the-early-modern-world-tracey-a-sowerby/

ebookmass.com

The Returning Hero: Nostoi and Traditions of Mediterranean Settlement Simon Hornblower (Editor)

https://ebookmass.com/product/the-returning-hero-nostoi-andtraditions-of-mediterranean-settlement-simon-hornblower-editor/

ebookmass.com

High Stakes Danielle Steel

https://ebookmass.com/product/high-stakes-danielle-steel/

ebookmass.com

Language, Biology and Cognition: A Critical Perspective

1st ed. Edition Prakash Mondal

https://ebookmass.com/product/language-biology-and-cognition-acritical-perspective-1st-ed-edition-prakash-mondal/

ebookmass.com

A Cowboy State of Mind 1st Edition Jennie Marts

https://ebookmass.com/product/a-cowboy-state-of-mind-1st-editionjennie-marts/

ebookmass.com

John Sharp

MICROSOFT VISUAL C# STEP BY STEP, TENTH EDITION

Published with the authorization of Microsoft Corporation by: Pearson Education, Inc.

Copyright © 2022 by Agylia Group Ltd.

All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms, and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearson.com/permissions.

No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.

ISBN-13: 978-0-13-761983-2

ISBN-10: 0-13-761983-9

Library of Congress Control Number: 2022930224

ScoutAutomatedPrintCode

TRADEMARKS

Microsoft and the trademarks listed at http://www.microsoft.com on the “Trademarks” webpage are trademarks of the Microsoft group of companies. All other marks are property of their respective owners.

WARNING AND DISCLAIMER

Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The author, the publisher, and Microsoft Corporation

shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the programs accompanying it.

SPECIAL SALES

For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@pearsoned.com or (800) 382-3419.

For government sales inquiries, please contact governmentsales@pearsoned.com.

For questions about sales outside the U.S., please contact intlcs@pearson.com.

Editor-in-Chief: Brett Bartow

Executive Editor: Loretta Yates

Sponsoring Editor: Charvi Arora

Development Editor: Kate Shoup

Managing Editor: Sandra Schroeder

Senior Project Editor: Tracey Croom

Production Editor: Dan Foster

Copy Editor: Dan Foster

Indexer: Valerie Haynes Perry

Proofreader: Kim Wimpsett

Technical Editor: David Franson

Editorial Assistant: Cindy Teeters

Cover Designer: Twist Creative, Seattle

Compositor: Danielle Foster

Pearson’s Commitment to Diversity, Equity, and Inclusion

Pearson is dedicated to creating bias-free content that reflects the diversity of all learners. We embrace the many dimensions of diversity, including but not limited to race, ethnicity, gender, socioeconomic status, ability, age, sexual orientation, and religious or political beliefs.

Education is a powerful force for equity and change in our world. It has the potential to deliver opportunities that improve lives and enable economic mobility. As we work with authors to create content for every product and service, we acknowledge our responsibility to demonstrate inclusivity and incorporate diverse scholarship so that everyone can achieve their potential through learning. As the world’s leading learning company, we have a duty to help drive change and live up to our purpose to help more people create a better life for themselves and to create a better world.

Our ambition is to purposefully contribute to a world where:

Everyone has an equitable and lifelong opportunity to succeed through learning.

Our educational products and services are inclusive and represent the rich diversity of learners.

Our educational content accurately reflects the histories and experiences of the learners we serve.

Our educational content prompts deeper discussions with learners and motivates them to expand their own learning (and worldview).

While we work hard to present unbiased content, we want to hear from you about any concerns or needs with this Pearson product so that we can investigate and address them.

Please contact us with concerns about any potential bias at https://www.pearson.com/report-bias.html.

Contents at a Glance

Acknowledgments

About the author

Introduction

PART I INTRODUCING MICROSOFT VISUAL C# AND MICROSOFT VISUAL STUDIO 2022

CHAPTER 1 Welcome to C#

CHAPTER 2 Working with variables, operators, and expressions

CHAPTER 3 Writing methods and applying scope

CHAPTER 4 Using decision statements

CHAPTER 5 Using compound assignment and iteration statements

CHAPTER 6 Managing errors and exceptions

PART II UNDERSTANDING THE C# OBJECT MODEL

CHAPTER 7 Creating and managing classes and objects

CHAPTER 8 Understanding values and references

CHAPTER 9 Creating value types with enumerations and structures

CHAPTER 10 Using arrays

CHAPTER 11 Understanding parameter arrays

CHAPTER 12 Working with inheritance

CHAPTER 13 Creating interfaces and defining abstract classes

CHAPTER 14 Using garbage collection and resource management

PART III UNDERSTANDING THE C# OBJECT MODEL

CHAPTER 15 Implementing properties to access fields

CHAPTER 16 Handling binary data and using indexers

CHAPTER 17 Introducing generics

CHAPTER 18 Using collections

CHAPTER 19 Enumerating collections

CHAPTER 20 Decoupling application logic and handling events

CHAPTER 21 Querying in-memory data by using query expressions

CHAPTER 22 Operator overloading

PART IV BUILDING UNIVERSAL WINDOWS PLATFORM APPLICATIONS WITH C#

CHAPTER 23 Improving throughput by using tasks

CHAPTER 24 Improving response time by performing asynchronous operations

CHAPTER 25 Implementing the user interface for a Universal Windows Platform app

CHAPTER 26 Displaying and searching for data in a Universal Windows Platform app

CHAPTER 27 Accessing a remote database from a Universal Windows Platform app Index

Contents Acknowledgments

About the author

Introduction

PART I INTRODUCING MICROSOFT VISUAL C# AND MICROSOFT VISUAL STUDIO 2022

Chapter 1 Welcome to C#

Writing your first C# program

Beginning programming with the Visual Studio 2022 environment

Writing your first program using Visual Studio 2022

Using namespaces

Namespaces and assemblies

Commenting code

Creating a graphical application

Examining the Universal Windows Platform app

Adding code to the graphical application

Summary

Quick Reference

Chapter 2 Working with variables, operators, and expressions

Understanding statements

Using identifiers

Identifying keywords

Using variables

Naming variables

Declaring variables

Specifying numeric values

Working with primitive data types

Unassigned local variables

Displaying primitive data type values

Using arithmetic operators

Operators and types

Examining arithmetic operators

Controlling precedence

Using associativity to evaluate expressions

Associativity and the assignment operator

Incrementing and decrementing variables

Prefix and postfix

Declaring implicitly typed local variables

Summary

Quick Reference

Chapter 3 Writing methods and applying scope

Creating methods

Declaring a method

Returning data from a method

Using expression-bodied methods

Calling methods

Specifying the method call syntax

Returning multiple values from a method

Applying scope

Defining local scope

Defining class scope

Overloading methods

Writing methods

Using the Visual Studio Debugger to step through methods

Refactoring code

Nesting methods

Using optional parameters and named arguments

Defining optional parameters

Passing named arguments

Resolving ambiguities with optional parameters and named arguments

Summary

Quick reference

Chapter 4 Using decision statements

Declaring Boolean variables

Using Boolean operators

Understanding equality and relational operators

Understanding conditional logical operators

Short-circuiting

Summarizing operator precedence and associativity

Pattern matching

Using if statements to make decisions

Understanding if statement syntax

Using blocks to group statements

Cascading if statements

Using switch statements

Understanding switch statement syntax

Following the switch statement rules

Using switch expressions with pattern matching

Summary

Quick reference

Chapter 5 Using compound assignment and iteration statements

Using compound assignment operators

Writing while statements

Writing for statements

Writing do statements

Summary

Quick reference

Chapter 6 Managing errors and exceptions

Trying code and catching exceptions

Unhandled exceptions

Using multiple catch handlers

Catching multiple exceptions

Filtering exceptions

Propagating exceptions

Using checked and unchecked integer arithmetic

Writing checked statements

Writing checked expressions

Throwing exceptions

Using throw expressions

Using a finally block

Summary

Quick reference

PART II UNDERSTANDING THE C# OBJECT MODEL

Chapter 7 Creating and managing classes and objects

Understanding classification

The purpose of encapsulation

Defining and using a class

Controlling accessibility

Working with constructors

Overloading constructors

Deconstructing an object

Understanding static methods and data

Creating a shared field

Creating a static field by using the const keyword

Understanding static classes

Static using statements

Anonymous classes

Summary

Quick reference

Chapter 8 Understanding values and references

Copying value type variables and classes

Understanding null values and nullable types

The null-conditional and null-coalescing operators

Using nullable types

Understanding the properties of nullable types

Using ref and out parameters

Creating ref parameters

Creating out parameters

How computer memory is organized

Using the stack and the heap

The System.Object class

Boxing

Unboxing

Casting data safely

The is operator

The as operator

The switch statement revisited

Summary

Quick reference

Chapter 9 Creating value types with enumerations and structures

Working with enumerations

Declaring an enumeration

Using an enumeration

Choosing enumeration literal values

Choosing an enumeration’s underlying type

Working with structures

Declaring a structure

Understanding differences between structures and classes

Declaring structure variables

Understanding structure initialization

Copying structure variables

Summary

Quick reference

Chapter 10 Using arrays

Declaring array variables

Creating an array instance

Populating and using an array

Creating an implicitly typed array

Accessing an individual array element

Accessing a series of array elements

Iterating through an array

Passing arrays as parameters or return values for a method

Copying arrays

Using multidimensional arrays

Creating jagged arrays

Accessing arrays that contain value types

Summary

Quick reference

Chapter 11 Understanding parameter arrays

Overloading: a recap

Using array arguments

Declaring a params array

Using params object[ ]

Using a params array

Comparing parameter arrays and optional parameters

Summary

Quick reference

Chapter 12 Working with inheritance

What is inheritance?

Using inheritance

The System.Object class revisited

Calling base-class constructors

Assigning classes

Declaring new methods

Declaring virtual methods

Declaring override methods

Understanding protected access

Creating extension methods

Summary

Quick reference

Chapter 13 Creating interfaces and defining abstract classes

Understanding interfaces

Defining an interface

Implementing an interface

Referencing a class through its interface

Working with multiple interfaces

Explicitly implementing an interface

Handling versioning with interfaces

Interface restrictions

Defining and using interfaces

Abstract classes

Abstract methods

Sealed classes

Sealed methods

Implementing and using an abstract class

Summary

Quick reference

Chapter 14 Using garbage collection and resource management

The life and times of an object

Writing finalizers

Why use the garbage collector?

How does the garbage collector work?

Recommendations

Resource management

Disposal methods

Exception-safe disposal

The using statement and the IDisposable interface

Calling the Dispose method from a finalizer

Implementing exception-safe disposal

Handling asynchronous disposal

Summary

Quick reference

PART III UNDERSTANDING THE C# OBJECT MODEL

Chapter 15 Implementing properties to access fields

Implementing encapsulation by using methods

What are properties?

Using properties

Read-only properties

Write-only properties

Property accessibility

Understanding property restrictions

Declaring interface properties

Replacing methods with properties

Pattern-matching with properties

Generating automatic properties

Initializing objects by using properties

Automatic properties and immutability

Using records with properties to implement lightweight structures

Summary

Quick reference

Chapter 16 Handling binary data and using indexers

What is an indexer?

Storing binary values

Displaying binary values

Manipulating binary values

Solving the same problems using indexers

Understanding indexer accessors

Comparing indexers and arrays

Indexers in interfaces

Using indexers in a Windows application

Summary

Quick reference

Chapter 17 Introducing generics

The problem: Issues with the object type

The generics solution

Generics vs. generalized classes

Generics and constraints

Creating a generic class

The theory of binary trees

Building a binary tree class by using generics

Creating a generic method

Defining a generic method to build a binary tree

Variance and generic interfaces

Covariant interfaces

Contravariant interfaces

Summary

Quick reference

Chapter 18 Using collections

What are collection classes?

The List<T> collection class

The LinkedList<T> collection class

The Queue<T> collection class

The PriorityQueue<TElement, TPriority> collection class

The Stack<T> collection class

The Dictionary<TKey, TValue> collection class

The SortedList<TKey, TValue> collection class

The HashSet<T> collection class

Using collection initializers

Find methods, predicates, and lambda expressions

The forms of lambda expressions

Lambda expressions and anonymous methods

Comparing arrays and collections

Summary

Quick reference

Chapter 19 Enumerating collections

Enumerating the elements in a collection

Manually implementing an enumerator

Implementing the IEnumerable interface

Implementing an enumerator by using an iterator

A simple iterator

Defining an enumerator for the Tree<TItem> class by using an iterator

Summary

Quick reference

Chapter 20 Decoupling application logic and handling events

Understanding delegates

Examples of delegates in the .NET class library

The automated factory scenario

Declaring and using delegates

Lambda expressions and delegates

Enabling notifications by using events

Declaring an event

Subscribing to an event

Unsubscribing from an event

Raising an event

Understanding user-interface events

Using events

Summary

Quick reference

Chapter 21 Querying in-memory data by using query expressions

What is LINQ?

Using LINQ in a C# application

Selecting data

Filtering data

Ordering, grouping, and aggregating data

Joining data

Using query operators

Querying data in Tree<TItem> objects

LINQ and deferred evaluation

Summary

Quick reference

Chapter 22 Operator overloading

Understanding operators

Operator constraints

Overloaded operators

Creating symmetric operators

Understanding compound assignment evaluation

Declaring increment and decrement operators

Comparing operators in structures and classes

Defining operator pairs

Implementing operators

Overriding the equality operators

Understanding conversion operators

Providing built-in conversions

Implementing user-defined conversion operators

Creating symmetric operators, revisited

Writing conversion operators

Summary

Quick reference

PART IV BUILDING UNIVERSAL WINDOWS

PLATFORM APPLICATIONS WITH C#

Chapter 23 Improving throughput by using tasks

Why perform multitasking by using parallel processing?

The rise of the multicore processor

Implementing multitasking by using Microsoft .NET

Tasks, threads, and the ThreadPool

Creating, running, and controlling tasks

Using the Task class to implement parallelism

Abstracting tasks by using the Parallel class

When not to use the Parallel class

Canceling tasks and handling exceptions

The mechanics of cooperative cancellation

Handling task exceptions by using the AggregateException class

Using continuations with canceled and faulted tasks

Summary

Quick reference

Chapter 24 Improving response time by performing asynchronous operations

Implementing asynchronous methods

Defining asynchronous methods: the problem

Defining asynchronous methods: the solution

Defining asynchronous methods that return values

Asynchronous method pitfalls

Asynchronous methods and the Windows Runtime APIs

Tasks, memory allocation, and efficiency

Using PLINQ to parallelize declarative data access

Using PLINQ to improve performance while iterating through a collection

Canceling a PLINQ query

Synchronizing concurrent access to data

Locking data

Synchronization primitives for coordinating tasks

Canceling synchronization

The concurrent collection classes

Using a concurrent collection and a lock to implement thread-safe data access

Summary

Quick reference

Chapter 25 Implementing the user interface for a Universal Windows Platform app

Features of a Universal Windows Platform app

Using the Blank App template to build a Universal Windows Platform app

Implementing a scalable user interface

Implementing a tabular layout by using a Grid control

Adapting the layout by using the Visual State Manager

Applying styles to a UI

Summary

Quick reference

Chapter 26 Displaying and searching for data in a Universal Windows Platform app

Implementing the Model-View-ViewModel pattern

Displaying data by using data binding

Modifying data by using data binding

Using data binding with a ComboBox control

Creating a ViewModel

Adding commands to a ViewModel

Summary

Quick reference

Chapter 27 Accessing a remote database from a Universal Windows Platform app

Retrieving data from a database

Creating an entity model

Creating and using a REST web service

Updating the UWP application to use the web service

Searching for data in the Customers app

Inserting, updating, and deleting data through a REST web service

Summary

Quick reference

Index

Acknowledgments

Hoo boy! Welcome to the 10th edition. In the acknowledgments to previous editions, I have made references to painting the Forth Railway Bridge and Sisyphus pushing the rock as never-ending tasks. In the future, maybe the role of updating Microsoft C# Step By Step will be added to this legendary list. That said, writing and updating books is far more rewarding than wielding a brush or rolling a stone up a hill forever and a day, with the added bonus that I can retire at some point.

Despite the fact that my name is on the cover, authoring a book such as this is far from a one-man project. I’d like to thank the following people who have provided unstinting support and assistance throughout this endeavor.

First, Loretta Yates at Pearson Education, who took on the role of prodding me into action and ever-so-gently tying me down to well-defined deliverables and hand-off dates. Without her initial impetus and cajoling, this project would not have gotten off the ground.

Next, Charvi Arora and her tireless team of editors, especially Kate Shoup and Dan Foster, who ensured that my grammar remained at least semiacceptable and picked up on the missing words and nonsense phrases in the text. Also, David Fransen, who had the unenviable task of reviewing and testing the code and exercises. I know from experience that this can be a thankless and frustrating task, but the hours spent and the resulting feedback can only make for a better book. Of course, any errors that remain are entirely my responsibility, and I am happy to listen to feedback from any reader.

As ever, I must also thank Diana, my better half, who keeps me sane, fed, and watered. During Covid-19 lockdown, she felt that our house wasn’t crowded enough, so she brought two rather manic kittens into the family. The dogs are now terrified, but we have endless hours of fun putting the curtains back up and playing “hunt the mouse/frog/spider or whatever they have captured and brought indoors.” I wouldn’t have home-life any other way.

And lastly, to James and Frankie, who have both now flown the nest. James has spent the last couple of years working for the British government in Manila (he says). Judging by the photos, it seems more like he has been on a touring holiday of the beaches of Southeast Asia. Frankie has remained closer to home so she can pop in and catch the mice/frogs/spiders from time to time. By the way, to those developers she manages at her place of work, it’s time for you to make her a cup of tea!

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.