Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

C# 13 Programming Essentials - .NET 9 Edition: Learn C# and .Net 9 Programming Using Visual Studio Code
C# 13 Programming Essentials - .NET 9 Edition: Learn C# and .Net 9 Programming Using Visual Studio Code
C# 13 Programming Essentials - .NET 9 Edition: Learn C# and .Net 9 Programming Using Visual Studio Code
Ebook529 pages3 hours

C# 13 Programming Essentials - .NET 9 Edition: Learn C# and .Net 9 Programming Using Visual Studio Code

Rating: 0 out of 5 stars

()

Read preview

About this ebook

This book is a comprehensive guide to mastering the C# 13 programming language and the .NET 9 SDK, providing a thorough learning experience for both beginners and experienced developers. With 31 detailed chapters, 30 online knowledge quizzes, and access to downloadable project code, this guide is structured to support your journey from basic concepts to advanced programming techniques, all within the Visual Studio Code environment.


We will start by introducing the foundational components of the C# ecosystem, providing an overview of the Common Language Infrastructure (CLI), the Common Intermediate Language (CIL), and the Virtual Execution System (VES). These initial sections will offer a deeper understanding of the platform’s architecture. Following that, we will provide step-by-step instructions for installing and using the Visual Studio Code environment.


As you advance, you will learn about the foundational principles of the C# language. This will include exploring topics such as variables, constants, operators, flow control, and loops. These basic concepts will then be expanded to cover object-oriented programming (OOP), with an emphasis on inheritance, abstract classes, interfaces, and structures.


Beyond the basics, this book advances into more specialized areas, including string manipulation, working with arrays and collections, handling exceptions, and implementing asynchronous programming techniques. These sections are designed to deepen your understanding and equip you with the skills necessary to build more sophisticated apps.


Whether you are new to programming or seeking to refine your skills, C# 13 Programming Essentials - .NET 9 Edition offers the knowledge and practical guidance you need to succeed in C# development.

LanguageEnglish
Release dateOct 17, 2024
ISBN9781965764015
C# 13 Programming Essentials - .NET 9 Edition: Learn C# and .Net 9 Programming Using Visual Studio Code

Read more from Neil Smyth

Related to C# 13 Programming Essentials - .NET 9 Edition

Related ebooks

Programming For You

View More

Reviews for C# 13 Programming Essentials - .NET 9 Edition

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    C# 13 Programming Essentials - .NET 9 Edition - Neil Smyth

    Cover of C# 13 Programming Essentials - .NET 9 Edition

    C# 13 Programming

    Essentials

    .NET 9 Edition

    C# 13 Programming Essentials - .NET 9 Edition

    ISBN-13: 978-1-965764-01-5

    © 2024 Neil Smyth / Payload Media, Inc. All Rights Reserved.

    This book is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights reserved.

    The content of this book is provided for informational purposes only. Neither the publisher nor the author offers any warranties or representation, express or implied, with regard to the accuracy of information contained in this book, nor do they accept any liability for any loss or damage arising from any errors or omissions.

    This book contains trademarked terms that are used solely for editorial purposes and to the benefit of the respective trademark owner. The terms used within this book are not intended as infringement of any trademarks.

    Rev: 1.0

    Copyright

    https://www.payloadbooks.com

    Table of Contents

    1. Start Here

    1.1 Source code download

    1.2 Feedback

    1.3 Errata

    1.4 Take the knowledge tests

    2. The History of Programming Languages and C#

    2.1 The history of programming languages

    2.2 What exactly is C#?

    2.3 Who is using C#?

    2.4 Take the knowledge test

    2.5 Summary

    3. C# Infrastructure

    3.1 The Common Language Infrastructure (CLI)

    3.2 Common Intermediate Language (CIL)

    3.3 Virtual Execution System (VES)

    3.4 Common Type System (CTS) & Common Language Specification (CLS)

    3.5 The Framework (Base Class and Framework Class Libraries)

    3.6 Implementations of the CLI

    3.7 Take the knowledge test

    3.8 Summary

    4. Installing Visual Studio Code, C# and .NET 9

    4.1 Installing the .NET 9 SDK

    4.1.1 Installing .NET 9 on Windows

    4.1.2 Installing .NET 9 on macOS

    4.1.3 Installing .NET 9 on Red Hat Linux-based distributions

    4.1.4 Installing the .NET 9 on Debian/Ubuntu distributions

    4.1.5 Installing .Net 9 from the Linux binaries

    4.2 Downloading Visual Studio Code

    4.3 Installing on Windows

    4.4 Installing on macOS

    4.5 Installing on Linux

    4.5.1 Debian/Ubuntu

    4.5.2 Red Hat-based distributions

    4.6 Customizing Visual Studio Code

    4.7 Adding the C# Dev Kit extension

    4.8 Take the knowledge test

    4.9 Summary

    5. A Guided Tour of Visual Studio Code

    5.1 Workspaces, projects, and solutions

    5.2 The VS Code main window

    5.3 The Command Palette

    5.4 Splitting the editor window

    5.5 Zen mode

    5.6 Learning with the Editor Playground

    5.7 Take the knowledge test

    5.8 Summary

    6. Creating an Example C# App in VS Code

    6.1 Creating the SampleApp project

    6.2 Reviewing the SampleApp project

    6.3 Writing the app code

    6.4 Top-level statements and the Main method

    6.5 Take the knowledge test

    6.6 Summary

    7. C# Variables and Constants

    7.1 What is a C# variable?

    7.2 Type annotations and implicit typing

    7.3 What is a C# constant?

    7.4 Integer types

    7.5 Floating-point Variables

    7.6 Decimal type

    7.7 Boolean type

    7.8 Character data type

    7.9 Special characters

    7.10 String data type

    7.11 Verbatim string literals

    7.12 String interpolation

    7.13 Type casting

    7.13.1 Implicit casting

    7.13.2 Explicit casting

    7.13.3 Identifying variable’s type

    7.14 Take the knowledge test

    7.15 Summary

    8. C# Operators and Expressions

    8.1 What is an expression?

    8.2 The basic assignment operator

    8.3 C# arithmetic operators

    8.4 C# operator precedence

    8.5 Compound assignment operators

    8.6 Increment and decrement operators

    8.7 Comparison operators

    8.8 Boolean logical operators

    8.9 Range and index operators

    8.10 The ternary operator

    8.11 Null-coalescing operators

    8.12 Bitwise Operators

    8.12.1 Bitwise NOT

    8.12.2 Bitwise AND

    8.12.3 Bitwise OR

    8.12.4 Bitwise XOR

    8.12.5 Bitwise Left Shift

    8.12.6 Bitwise Right Shift

    8.13 Compound Bitwise Operators

    8.14 Take the knowledge test

    8.15 Summary

    9. C# Conditional Control Flow

    9.1 Looping vs. conditional control flow

    9.2 Using the if statement

    9.3 Using if … else … statements

    9.4 Using if … else if … statements

    9.5 Take the knowledge test

    9.6 Summary

    10. The C# switch Statement

    10.1 Why use the switch statement?

    10.2 Using the switch statement

    10.3 A switch statement example

    10.4 Explaining the example

    10.5 Using switch expressions

    10.6 Using goto in a C# switch statement

    10.7 Using continue in a C# switch statement

    10.8 Take the knowledge test

    10.9 Summary

    11. C# Looping with the for Statement

    11.1 Why use loops?

    11.2 C# loop variable scope

    11.3 Creating an infinite for loop

    11.4 Breaking out of a for loop

    11.5 Nested for loops

    11.6 Breaking from nested loops

    11.7 Continuing for loops

    11.8 The C# foreach statement

    11.9 Take the knowledge test

    11.10 Summary

    12. C# Looping with do and while Statements

    12.1 The C# while loop

    12.2 C# do … while loops

    12.3 Breaking from loops

    12.4 The continue statement

    12.5 Take the knowledge test

    12.6 Summary

    13. An Introduction to C# Object-Oriented Programming

    13.1 What is an object?

    13.2 What is a class?

    13.3 Creating the ObjectDemo project

    13.4 Declaring a C# class

    13.5 Access modifiers

    13.6 Creating C# class members

    13.7 Fields vs. properties

    13.8 Adding members to the BankAccount class

    13.9 Static, read-only, and const data members

    13.10 Instantiating an object from a C# class

    13.11 Accessing C# object members

    13.12 Adding methods to a C# class

    13.13 C# constructors

    13.14 C# primary constructors

    13.15 C# finalizers

    13.16 The this keyword

    13.17 Take the knowledge test

    13.18 Summary

    14. C# Methods

    14.1 What is a method?

    14.2 Methods vs. functions

    14.3 Parameter or argument?

    14.4 How to declare a C# function

    14.5 Creating the MethodDemo project

    14.6 Declaring a C# class file

    14.7 Calling a C# method

    14.8 Handling return values

    14.9 Passing arguments to a method

    14.9.1 Named arguments

    14.9.2 Optional arguments

    14.10 Handling variable numbers of arguments

    14.11 C# in, out, and ref parameter modifiers

    14.12 Take the knowledge test

    14.13 Summary

    15. C# Delegates

    15.1 What is a delegate?

    15.2 Declaring a delegate

    15.3 Using delegates

    15.4 Creating the DelegateDemo project

    15.5 A C# delegate example

    15.6 Multicast delegates

    15.7 Passing a delegate to a method

    15.8 Take the knowledge test

    15.9 Summary

    16. C# Anonymous Methods, Lambdas, and Local Functions

    16.1 Anonymous methods

    16.2 Creating the LambdaDemo project

    16.3 Lambdas

    16.4 Passing multiple parameters

    16.5 Passing no parameters

    16.6 Local functions

    16.7 Creating the LocalFunctions project

    16.8 Recursive local functions

    16.9 Lambdas vs. local functions

    16.10 Take the knowledge test

    16.11 Summary

    17. C# Inheritance

    17.1 What is inheritance?

    17.2 A C# inheritance example

    17.3 Creating a subclass in C#

    17.4 Passing arguments to the base class constructor

    17.5 Overriding inherited methods

    17.6 Take the knowledge test

    17.7 Summary

    18. C# Abstract Classes

    18.1 What is a C# abstract class?

    18.2 Abstract members

    18.3 Declaring a C# abstract class

    18.4 Deriving from an abstract class

    18.5 Creating the AbstractClassDemo project

    18.6 Abstract vs. virtual members

    18.7 Take the knowledge test

    18.8 Summary

    19. C# Interfaces

    19.1 Understanding C# interfaces

    19.2 Declaring an interface

    19.3 Creating the InterfaceDemo project

    19.4 Adding a C# interface file

    19.5 Interface data members

    19.6 Take the knowledge test

    19.7 Summary

    20. C# Structures

    20.1 An overview of C# structures

    20.2 Creating the StructureDemo project

    20.3 Value types vs. reference types

    20.4 Adding the Struct declaration

    20.5 Read-only structures

    20.6 Take the knowledge test

    20.7 Summary

    21. C# Tuple Type

    21.1 Creating the TupleDemo project

    21.2 Declaring a Tuple

    21.3 Accessing tuple values

    21.4 Tuple field names

    21.5 Returning tuples from methods

    21.6 Tuples as method parameters

    21.7 Take the knowledge test

    21.8 Summary

    22. C# Namespaces

    22.1 Understanding scope

    22.2 An overview of namespaces

    22.3 Creating the NamespaceDemo project

    22.4 Declaring namespaces

    22.5 Accessing namespace members

    22.6 Namespaces and the using keyword

    22.7 Nested namespaces

    22.8 Aliases and the namespace alias operator

    22.9 File scoped namespaces

    22.10 Take the knowledge test

    22.11 Summary

    23. C# Exception Handling

    23.1 Understanding exception handling

    23.2 Creating the ExceptionDemo project

    23.3 Throwing exceptions

    23.4 Handling exceptions

    23.5 Creating exception filters with the when keyword

    23.6 Using finally blocks

    23.7 Using the try-finally Statement

    23.8 Re-throwing exceptions

    23.9 Creating custom exception types

    23.10 Take the knowledge test

    23.11 Summary

    24. Asynchronous Programming in C#

    24.1 An overview of threads

    24.2 The main thread

    24.3 Asynchronous programming in C#

    24.4 Creating the AsyncDemo project

    24.5 Synchronous code

    24.6 Understanding the C# Task class

    24.7 Declaring asynchronous methods

    24.8 Introducing the await operator

    24.9 Asynchronous calls from synchronous functions

    24.10 Canceling asynchronous tasks

    24.11 Take the knowledge test

    24.12 Summary

    25. Creating 2D, 3D, and Jagged Arrays in C#

    25.1 Creating arrays in C#

    25.2 Declaring multidimensional arrays

    25.3 Declaring jagged arrays

    25.4 Take the knowledge test

    25.5 Summary

    26. Accessing and Sorting C# Array Elements

    26.1 Creating the ArrayDemo Project

    26.2 Getting the number of dimensions of an array

    26.3 Accessing array elements

    26.4 Array iteration

    26.5 Working with ranges

    26.6 C# index from end operator

    26.7 Sorting C# arrays

    26.8 Clearing C# arrays

    26.9 Take the knowledge test

    26.10 Summary

    27. C# List Collections

    27.1 Creating the CollectionDemo Project

    27.2 Introducing the C# Collection Classes

    27.3 Creating C# list collections with List

    27.4 Adding items to lists

    27.5 Initializing a list with multiple values

    27.6 Accessing list items

    27.7 Removing items from lists

    27.8 Inserting items into a list

    27.9 Sorting lists in C#

    27.10 Finding items in a C# list

    27.11 Obtaining information about a list

    27.12 Clearing C# lists

    27.13 Take the knowledge test

    27.14 Summary

    28. C# Dictionary Collections

    28.1 Creating the DictionaryDemo Project

    28.2 Dictionary initialization

    28.3 Dictionary item count

    28.4 Dictionary iteration

    28.5 Adding and removing dictionary entries

    28.6 Accessing and updating dictionary items

    28.7 Checking if a key or value exists

    28.8 Take the knowledge test

    28.9 Summary

    29. C# File and Directory Handling

    29.1 Introducing the System.IO classes

    29.2 Understanding paths in C#

    29.3 Creating the FileDemo project

    29.4 Current working directory

    29.5 Checking if a directory exists

    29.6 Creating a Directory

    29.7 Deleting a Directory

    29.8 Changing the current working directory

    29.9 Handling File and Directory Exceptions

    29.10 File handling using the File class

    29.10.1 Checking if a file exists

    29.10.2 Creating and opening files

    29.10.3 Reading and writing using the File class

    29.11 Deleting, copying, and moving files

    29.12 File I/O with streams

    29.13 Asynchronous file handling

    29.14 Working with binary streams

    29.15 Take the knowledge test

    29.16 Summary

    30. C# Strings

    30.1 Creating the StringsDemo Project

    30.2 Creating strings in C#

    30.3 Obtaining the length of a C# string

    30.4 Treating strings as arrays

    30.5 String character iteration

    30.6 Concatenating strings

    30.7 Comparing strings

    30.8 Changing string case

    30.9 Splitting a string into multiple parts

    30.10 Trimming and padding strings

    30.11 String replacement

    30.12 Take the knowledge test

    30.13 Summary

    31. C# String Formatting

    31.1 The Syntax of the string Format() method

    31.2 Creating the StringFormatDemo project

    31.3 A simple string formatting example

    31.4 Using format controls

    31.5 A simple format control example

    31.6 C# string Format() format controls

    31.7 Take the knowledge test

    31.8 Summary

    32. C# Dates and Times

    32.1 Creating the DateTimeDemo project

    32.2 Creating a C# DateTime object

    32.3 Getting the current system time and date

    32.4 Adding to or subtracting from dates and times

    32.5 Retrieving parts of a date and time

    32.6 Take the knowledge test

    32.7 Summary

    Index

    1. Start Here

    This book is a comprehensive guide to mastering the C# 13 programming language and the .NET 9 SDK, providing a thorough learning experience for both beginners and experienced developers. With 31 detailed chapters, 30 online knowledge quizzes, and access to downloadable project code, this guide is structured to support your journey from basic concepts to advanced programming techniques, all within the Visual Studio Code environment.

    We will start by introducing the foundational components of the C# ecosystem, providing an overview of the Common Language Infrastructure (CLI), the Common Intermediate Language (CIL), and the Virtual Execution System (VES). These initial sections will offer a deeper understanding of the platform’s architecture. Following that, we will provide step-by-step instructions for installing and using the Visual Studio Code environment.

    As you advance, you will learn about the foundational principles of the C# language. This will include exploring topics such as variables, constants, operators, flow control, and loops. These basic concepts will then be expanded to cover object-oriented programming (OOP), with an emphasis on inheritance, abstract classes, interfaces, and structures.

    Beyond the basics, this book advances into more specialized areas, including string manipulation, working with arrays and collections, handling exceptions, and implementing asynchronous programming techniques. These sections are designed to deepen your understanding and equip you with the skills necessary to build more sophisticated apps.

    Whether you are new to programming or seeking to refine your skills, C# 13 Programming Essentials - .NET 9 Edition offers the knowledge and practical guidance you need to succeed in C# development.

    1.1 Source code download

    The source code and Visual Studio Code project files for the examples contained in this book can be downloaded using the following link:

    https://www.payloadbooks.com/product/csharp13/

    After downloading and unzipping the file, you will find the projects in the C# Essentials workspace folder. In Visual Studio Code, you can open the workspace by selecting File -> Open Folder... from the menu bar, navigating to the workspace folder, and clicking Open to load the projects.

    1.2 Feedback

    We want you to be satisfied with your purchase of this book. Therefore, if you find any errors in the book or have any comments, questions, or concerns, please contact us at [email protected].

    1.3 Errata

    While we make every effort to ensure the accuracy of the content of this book, inevitably, a book covering a subject area of this size and complexity may include some errors and oversights. Any known issues with the book will be outlined, together with solutions, at the following URL:

    https://www.payloadbooks.com/csharp13-errata/

    If you find an error not listed in the errata, please email our technical support team at [email protected].

    1.4 Take the knowledge tests

    Look for this section at the end of most chapters and use the link or scan the QR code to take a knowledge quiz to test and reinforce your understanding of the covered topic. Use the following link to review the full list of tests available for this book:

    https://www.answertopia.com/4my3

    2. The History of Programming Languages and

    C#

    C# is part of the never-ending quest to make programming computers as easy and efficient as possible for humans. While it is easy to describe C# as another object-oriented programming language, the fact is that C# is an integral part of an entire development and execution infrastructure. The primary object of these initial chapters is to provide an overview of both the C# language and the infrastructure on which it relies.

    2.1 The history of programming languages

    The problem with programming is that computers think exclusively in numbers (0 and 1, to be precise), known as machine code, while humans communicate using words. In the early days, programmers entered machine code directly into computers to program them. This, as you can imagine, was a laborious and error-prone process. The next evolution was associating brief human-readable commands with the corresponding machine code. For example, a programmer could enter the command MOV to transfer a value from one microprocessor register to another. These commands would then be translated into machine code by a piece of software called an assembler, thereby giving this command syntax the name Assembly Language.

    Next came a series of high-level languages designed to make it easier for humans to write programs. These programs are written using a human-readable syntax and then either compiled to machine code by a compiler or interpreted by an interpreter on the processor’s behalf. Such languages include BASIC, COBOL, Pascal, and Fortran. Another language is C, which was created at AT&T Bell Labs in the late 1960s and early 1970s. Then, in the late 1970s and early 1980s, work started on an object-oriented approach to C programming, culminating in a new, object-oriented variant of C known as C++.

    The story, however, continues. The problem with C++ was that it was

    Enjoying the preview?
    Page 1 of 1