Easily get started programming using the ultra-versatile C# 7 and Visual Studio 2017
Beginning C# 7 Programming with Visual Studio 2017 is the beginner's ultimate guide to the world's most popular programming language. Whether you're new to programming entirely, or just new to C#, there has never been a better time to get started. The new C# 7 and Visual Studio 2017 updates feature a number of new tools and features that streamline the workflow, simplify the code, and make it easier than ever to build high-quality apps. This book walks you through everything you need to know, starting from the very basics, to have you programming in no time. You'll learn about variables, flow control, and object oriented programming, then move into Web and Windows programming as well as databases and XML. The companion website provides downloadable code examples, and practical Try It Out sections provide explicit, step-by-step instructions for writing your own useful, customizable code.
C# 7 can be used to build Windows applications, program Windows 10, and write Web apps when used alongside ASP.NET. With programming skills becoming de rigueur in fields far beyond the tech world, C# 7 is a great place to start building versatile, helpful skills. This book gets you started quickly and easily with instruction from a master-team of C# programmers.
Learn how to program using the world's leading programming language Build smarter, faster apps using the latest features in C# 7 and Visual Studio 2017 Find and fix bugs sooner, saving headaches down the line Integrate with all .NET Core, Azure applications, cloud services, Docker containers, and more The world of programming can seem intimidating to a beginner, and the prospect of learning a whole new "language" can seem daunting. Beginning C# 7 Programming with Visual Studio 2017 demystifies the process and shows you how to bring your ideas to life.
Author(s): Benjamin Perkins
Publisher: Wrox Press
Year: 2018
Language: English
Pages: 912
Cover
Title Page
Copyright
About the Authors
About the Technical Editor
Credits
Acknowledgments
Contents
Introduction
Who This Book is for
What This Book Covers
How This Book is Structured
The C# Language (Chapters 1–13)
Windows Programming (Chapters 14–15)
Cloud and Cross-Platform Programming (Chapters 16–19)
Data Access (Chapters 20–23)
Additional Techniques (Chapters 24–25)
What you Need to use This Book
Conventions
Source Code
Errata
Part I: The C# Language
Chapter 1: Introducing C#
What is the .NET Framework?
What’s in the .NET Framework?
.NET Standard and .NET Core
Writing Applications Using the .NET Framework and .NET Core
CIL and JIT
Assemblies
Managed Code
Garbage Collection
Fitting it Together
Linking
What Is C#?
Applications You Can Write with C#
C# in this Book
Visual Studio 2017
Visual Studio 2017 Products
Solutions
Chapter 2: Writing a C# Program
The Visual Studio 2017 Development Environment
Console Applications
The Solution Explorer
The Properties Window
The Error List Window
Desktop Applications
Chapter 3: Variables and Expressions
Basic C# Syntax
Basic C# Console Application Structure
Variables
Simple Types
Variable Naming
Literal Values
Binary Literals and Digit Separators
String Literals
Expressions
Mathematical Operators
Assignment Operators
Operator Precedence
Namespaces
Chapter 4: Flow Control
Boolean Logic
Boolean Bitwise and Assignment Operators
Operator Precedence Updated
Branching
The Ternary Operator
The if Statement
Checking More Conditions Using if Statements
The switch Statement
Looping
do Loops
while Loops
for Loops
Interrupting Loops
Infinite Loops
Chapter 5: More about Variables
Type Conversion
Implicit Conversions
Explicit Conversions
Explicit Conversions Using the Convert Commands
Complex Variable Types
Enumerations
Defining Enumerations
Structs
Defining Structs
Arrays
Declaring Arrays
foreach Loops
Pattern Matching with switch case expression
Multidimensional Arrays
Arrays of Arrays
String Manipulation
Chapter 6: Functions
Defining and Using Functions
Return Values
Parameters
Parameter Matching
Parameter Arrays
Reference and Value Parameters
Out Parameters
Tuples
Variable Scope
Variable Scope in Other Structures
Parameters and Return Values versus Global Data
Local Functions
The Main() Function
Struct Functions
Overloading Functions
Using Delegates
Chapter 7: Debugging and Error Handling
Debugging in Visual Studio
Debugging in Nonbreak (Normal) Mode
Outputting Debugging Information
Tracepoints
Diagnostics Output Versus Tracepoints
Debugging in Break Mode
Entering Break Mode
Monitoring Variable Content
Stepping through Code
Immediate and Command Windows
The Call Stack Window
Error Handling
try…catch…finally
Throw Expressions
Listing and Configuring Exceptions
Chapter 8: Introduction to Object-Oriented Programming
What Is Object-Oriented Programming?
What Is an Object?
Properties and Fields
Methods
Everything’s an Object
The Life Cycle of an Object
Constructors
Destructors
Static and Instance Class Members
Static Constructors
Static Classes
OOP Techniques
Interfaces
Disposable Objects
Inheritance
Polymorphism
Interface Polymorphism
Relationships between Objects
Containment
Collections
Operator Overloading
Events
Reference Types versus Value Types
OOP in Desktop Applications
Chapter 9: Defining Classes
Class Definitions in C#
Interface Definitions
System.Object
Constructors and Destructors
Constructor Execution Sequence
OOP Tools in Visual Studio
The Class View Window
The Object Browser
Adding Classes
Class Diagrams
Class Library Projects
Interfaces Versus Abstract Classes
Struct Types
Shallow Copying Versus Deep Copying
Chapter 10: Defining Class Members
Member Definitions
Defining Fields
Defining Methods
Defining Properties
Tuple Deconstruction
Refactoring Members
Automatic Properties
Additional Class Member Topics
Hiding Base Class Methods
Calling Overridden or Hidden Base Class Methods
The this Keyword
Using Nested Type Definitions
Interface Implementation
Implementing Interfaces in Classes
Explicit Interface Member Implementation
Additional Property Accessors
Partial Class Definitions
Partial Method Definitions
Example Application
Planning the Application
The Card Class
The Deck Class
Writing the Class Library
Adding the Suit and Rank Enumerations
Adding the Card Class
Adding the Deck Class
A Client Application for the Class Library
The Call Hierarchy Window
Chapter 11: Collections, Comparisons, and Conversions
Collections
Using Collections
Defining Collections
Indexers
Adding a Cards Collection to CardLib
Keyed Collections and IDictionary
Iterators
Iterators and Collections
Deep Copying
Adding Deep Copying to CardLib
Comparisons
Type Comparisons
Boxing and Unboxing
The is Operator
Pattern Matching with the is Operator Pattern Expression
Value Comparisons
Operator Overloading
Adding Operator Overloads to CardLib
The IComparable and IComparer Interfaces
Sorting Collections
Conversions
Overloading Conversion Operators
The as Operator
Chapter 12: Generics
What Are Generics?
Using Generics
Nullable Types
Operators and Nullable Types
The ?? Operator
The ?. Operator
Working with Nullable Types
The System.Collections.Generic Namespace
List
Sorting and Searching Generic Lists
Dictionary
Modifying CardLib to Use a Generic Collection Class
Defining Generic Types
Defining Generic Classes
The default Keyword
Constraining Types
Inheriting from Generic Classes
Generic Operators
Generic Structs
Defining Generic Interfaces
Defining Generic Methods
Defining Generic Delegates
Variance
Covariance
Contravariance
Chapter 13: Additional C# Techniques
The :: Operator and the Global Namespace Qualifier
Custom Exceptions
Adding Custom Exceptions to CardLib
Events
What Is an Event?
Handling Events
Defining Events
Multipurpose Event Handlers
The EventHandler and Generic EventHandler Types
Return Values and Event Handlers
Anonymous Methods
Expanding and Using CardLib
Attributes
Reading Attributes
Creating Attributes
Initializers
Object Initializers
Collection Initializers
Type Inference
Anonymous Types
Dynamic Lookup
The dynamic Type
Advanced Method Parameters
Optional Parameters
Optional Parameter Values
The OptionalAttribute Attribute
Optional Parameter Order
Named Parameters
Lambda Expressions
Anonymous Methods Recap
Lambda Expressions for Anonymous Methods
Lambda Expression Parameters
Lambda Expression Statement Bodies
Lambda Expressions as Delegates and Expression Trees
Lambda Expressions and Collections
Part II: Windows Programming
Chapter 14: Basic Desktop Programming
XAML
Separation of Concerns
XAML in Action
Namespaces
Code-Behind Files
The Playground
WPF Controls
Properties
Dependency Properties
Attached Properties
Events
Handling Events
Routed Events
Routed Commands
Control Types
Control Layout
Basic Layout Concepts
Stack Order
Alignment, Margins, Padding, and Dimensions
Border
Visual Debugging Tools
Layout Panels
Canvas
DockPanel
StackPanel
WrapPanel
Grid
The Game Client
The About Window
Designing the User Interface
The Image Control
The Label Control
The TextBlock Control
The Button Control
The Options Window
The TextBox Control
The CheckBox Control
The RadioButton Control
The ComboBox Control
The TabControl
Handling Events in the Options Window
Data Binding
The DataContext
Binding to Local Objects
Static Binding to External Objects
Dynamic Binding to External Objects
Starting a Game with the Listbox Control
Chapter 15: Advanced Desktop Programming
Creating and Styling Controls
Styles
Templates
Triggers
Animations
WPF User Controls
Implementing Dependency Properties
The Main Window
The Menu Control
Routed Commands with Menus
Putting It All Together
Refactoring the Domain Model
The ViewModel
Completing the Game
Part III: Cloud and Cross-Platform Programming
Chapter 16: Basic Cloud Programming
The Cloud, Cloud Computing, and the Cloud Optimized Stack
Cloud Patterns and Best Practices
Using Microsoft Azure C# Libraries to Create a Storage Container
Creating an ASP.NET 4.7 Web Site That Uses the Storage Container
Chapter 17: Advanced Cloud Programming and Deployment
Creating an ASP.NET Web API
Deploying and Consuming an ASP.NET Web API on Microsoft Azure
Scaling an ASP.NET Web API on Microsoft Azure
Chapter 18: .NET Standard and .NET Core
Cross-Platform Basics and Key “Must Know” Terms
What Is .NET Standard, and Why Is It Needed?
Shared Project, PCL, and .NET Standard
Referencing and Targeting Frameworks
What is .NET Core?
Cross Platform
Open Source
Optimized for the Cloud
Performance
Modular Design
Self-Contained Deployment Model
Building and Packaging a .NET Standard Library
Building a .NET Core Application with Visual Studio
Porting from .NET Framework to .NET Core
Identifying Third-Party Dependencies
Understanding Which Features Are Not Available
Upgrading the Current .NET Framework Target
Choosing the Platforms to Target for the Program
Chapter 19: ASP.NET and ASP.NET Core
Overview of Web Applications
Which ASP.NET to Use and Why
ASP.NET Web Forms
ASP.NET MVC
ASP.NET Web API
ASP.NET Core
ASP.NET Web Site versus ASP.NET Web Application Project Types
File Structure
Compiling
Deployment
Using ASP.NET Web Forms
Server Controls
Input Validation
State Management
Authentication and Authorization
Creating ASP.NET Core Web Applications
IIS and Kestrel
Razor Syntax
Input Validation
State Management
Authentication and Authorization
Dependency Injection
Part IV: Data Access
Chapter 20: Files
File Classes for Input and Output
The File and Directory Classes
The FileInfo Class
The DirectoryInfo Class
Path Names and Relative Paths
Streams
Classes for Using Streams
The FileStream Object
File Position
Reading Data
Writing Data
The StreamWriter Object
The StreamReader Object
Reading Data
Asynchronous File Access
Reading and Writing Compressed Files
Monitoring the File System
Chapter 21: XML and JSON
XML Basics
JSON Basics
XML Schemas
XML Document Object Model
The XmlDocument Class
The XmlElement Class
Changing the Values of Nodes
Inserting New Nodes
Deleting Nodes
Selecting Nodes
Converting XML to JSON
Searching XML with XPath
Chapter 22: LINQ
LINQ to XML
LINQ to XML Functional Constructors
Working with XML Fragments
LINQ Providers
LINQ Query Syntax
Declaring a Variable for Results Using the var Keyword
Specifying the Data Source: from Clause
Specify Condition: where Clause
Selecting Items: select Clause
Finishing Up: Using the foreach Loop
Deferred Query Execution
LINQ Method Syntax
LINQ Extension Methods
Query Syntax versus Method Syntax
Lambda Expressions
Ordering Query Results
Understanding the orderby Clause
Querying a Large Data Set
Using Aggregate Operators
Using the Select Distinct Query
Ordering by Multiple Levels
Using Group Queries
Using Joins
Chapter 23: Databases
Using Databases
Installing SQL Server Express
Entity Framework
A Code First Database
But Where Is My Database?
Navigating Database Relationships
Handling Migrations
Creating and Querying XML from an Existing Database
Part V: Additional Techniques
Chapter 24: Windows Communication Foundation
What Is WCF?
WCF Concepts
WCF Communication Protocols
Addresses, Endpoints, and Bindings
Contracts
Message Patterns
Behaviors
Hosting
WCF Programming
The WCF Test Client
Defining WCF Service Contracts
Data Contracts
Service Contracts
Operation Contracts
Message Contracts
Fault Contracts
Self-Hosted WCF Services
Chapter 25: Universal Apps
Getting Started
Windows Universal Apps
App Concepts and Design
Screen Orientation
Menus and Toolbars
Tiles and Badges
App Lifetime
Lock Screen Apps
App Development
Adaptive Displays
Relative Panel
Adaptive Triggers
FlipView
Sandboxed Apps
Disk Access
Serialization, Streams, and Async Programming
Navigation between Pages
The CommandBar Control
Managing State
Common Elements of Windows Store Apps
The Windows Store
Packaging an App
Creating the Package
Appendix : Exercise Solutions
Chapter 3 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Chapter 4 Solutions
Exercise 1
Exercise 2
Exercise 3
Chapter 5 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Exercise 6
Chapter 6 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Chapter 7 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Chapter 8 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Chapter 9 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Chapter 10 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Chapter 11 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Chapter 12 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Exercise 6
Chapter 13 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Exercise 6
Exercise 7
Exercise 8
Chapter 14 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Chapter 15 Solutions
Exercise 1
Exercise 2
Exercise 3
Chapter 16 Solutions
Exercise 1
Exercise 2
Chapter 17 Solutions
Exercise 1
Exercise 2
Chapter 20 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Exercise 6
Chapter 21 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Chapter 22 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Exercise 6
Chapter 23 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Chapter 24 Solutions
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
Chapter 25 Solutions
Exercise 1
Exercise 2
Index
EULA