Your hands-on guide to Visual C# fundamentals with Visual Studio 2022
Expand your expertise--and teach yourself the fundamentals of programming the latest version of Visual C# with Visual Studio 2022. This book provides software developers all the guidance, exercises, and code needed to start building responsive, scalable, cloud-connected applications that can run almost anywhere.
Discover how to:
Quickly start creating Visual C# code and projects with Visual Studio Work with variables, operators, expressions, methods, and program flow Build more robust apps with error, exception, and resource management Spot problems fast with the integrated Visual Studio 2022 debugger Master new default interface methods, static local functions, async disposable types, and other enhancements Make the most of the C# object model, and create functional data structures Leverage advanced properties, indexers, generics, and collection classes Create Windows 11 apps that share data, collaborate, and use cloud services Use lightweight records to build immutable reference types more easily Perform complex queries over object collections with LINQ Improve application throughput and response time with asynchronous methods Use delegates and decoupling to construct highly extensible systems Customize C# operator behavior over your own classes and structures Implement the powerful Model-View-ViewModel (MVVM) pattern Build UWP applications that retrieve complex data and present it intuitively
Author(s): John Sharp
Series: Microsoft Developer Professional
Edition: 10
Publisher: Microsoft Press
Year: 2022
Language: English
Tags: C #; C; #; CSharp; sharp; .NET; NET; dotNET
Cover Page
Title Page
Copyright Page
Pearson’s Commitment to Diversity, Equity, and Inclusion
Contents at a Glance
Contents
Acknowledgments
About the author
Introduction
Who should read this book
Who should not read this book
Finding your best starting point in this book
Conventions and features in this book
System requirements
Code samples
Errata and book support
Stay in touch
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
Summary
Quick Reference
Chapter 2. Working with variables, operators, and expressions
Understanding statements
Using identifiers
Identifying keywords
Using variables
Working with primitive data types
Using arithmetic operators
Incrementing and decrementing variables
Declaring implicitly typed local variables
Summary
Quick Reference
Chapter 3. Writing methods and applying scope
Creating methods
Calling methods
Applying scope
Using the Visual Studio Debugger to step through methods
Using optional parameters and named arguments
Summary
Quick reference
Chapter 4. Using decision statements
Declaring Boolean variables
Using Boolean operators
Using if statements to make decisions
Using switch statements
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
Using checked and unchecked integer arithmetic
Throwing exceptions
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
Understanding static methods and data
Anonymous classes
Summary
Quick reference
Chapter 8. Understanding values and references
Copying value type variables and classes
Understanding null values and nullable types
Using ref and out parameters
How computer memory is organized
Casting data safely
Summary
Quick reference
Chapter 9. Creating value types with enumerations and structures
Working with enumerations
Working with structures
Summary
Quick reference
Chapter 10. Using arrays
Declaring array variables
Creating an array instance
Populating and using an array
Copying arrays
Using multidimensional arrays
Accessing arrays that contain value types
Summary
Quick reference
Chapter 11. Understanding parameter arrays
Overloading: a recap
Using array arguments
Comparing parameter arrays and optional parameters
Summary
Quick reference
Chapter 12. Working with inheritance
What is inheritance?
Using inheritance
Creating extension methods
Summary
Quick reference
Chapter 13. Creating interfaces and defining abstract classes
Understanding interfaces
Abstract classes
Sealed classes
Summary
Quick reference
Chapter 14. Using garbage collection and resource management
The life and times of an object
Resource management
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?
Understanding property restrictions
Declaring interface properties
Generating automatic properties
Initializing objects by using properties
Using records with properties to implement lightweight structures
Summary
Quick reference
Chapter 16. Handling binary data and using indexers
What is an indexer?
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
Creating a generic class
Creating a generic method
Variance and generic interfaces
Summary
Quick reference
Chapter 18. Using collections
What are collection classes?
Using collection initializers
Find methods, predicates, and lambda expressions
Comparing arrays and collections
Summary
Quick reference
Chapter 19. Enumerating collections
Enumerating the elements in a collection
Implementing an enumerator 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
Lambda expressions and delegates
Enabling notifications by using events
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
LINQ and deferred evaluation
Summary
Quick reference
Chapter 22. Operator overloading
Understanding operators
Declaring increment and decrement operators
Comparing operators in structures and classes
Defining operator pairs
Implementing operators
Overriding the equality operators
Understanding 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
Canceling tasks and handling exceptions
Summary
Quick reference
Chapter 24. Improving response time by performing asynchronous operations
Implementing asynchronous methods
Using PLINQ to parallelize declarative data access
Synchronizing concurrent access to data
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
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
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
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
Code Snippets