Book Image

The C# Workshop

By : Jason Hales, Almantas Karpavicius, Mateus Viegas
4 (2)
Book Image

The C# Workshop

4 (2)
By: Jason Hales, Almantas Karpavicius, Mateus Viegas

Overview of this book

C# is a powerful, versatile language that can unlock a variety of career paths. But, as with any programming language, learning C# can be a challenging process. With a wide range of different resources available, it’s difficult to know where to start. That's where The C# Workshop comes in. Written and reviewed by industry experts, it provides a fast-paced, supportive learning experience that will quickly get you writing C# code and building applications. Unlike other software development books that focus on dry, technical explanations of the underlying theory, this Workshop cuts through the noise and uses engaging examples to help you understand how each concept is applied in the real world. As you work through the book, you'll tackle realistic exercises that simulate the type of problems that software developers work on every day. These mini-projects include building a random-number guessing game, using the publisher-subscriber model to design a web file downloader, creating a to-do list using Razor Pages, generating images from the Fibonacci sequence using async/await tasks, and developing a temperature unit conversion app which you will then deploy to a production server. By the end of this book, you'll have the knowledge, skills, and confidence to advance your career and tackle your own ambitious projects with C#.
Table of Contents (10 chapters)

About the Chapters

Chapter 1, Hello C#, introduces the fundamental concepts of the language, such as variables, constants, loops, and arithmetic and logical operators.

Chapter 2, Building Quality Object-Oriented Code, covers the basics of Object-oriented programming and its four pillars, before introducing the five main principles of clean coding—SOLID. This chapter also covers the latest features in the C# language.

Chapter 3, Delegates, Events, and Lambdas, introduces delegates and events, which form the core mechanism for communicating between objects, and lambda syntax, which offers a way to clearly express the intent of code.

Chapter 4, Data Structures and LINQ, covers the common collection classes that are used to store multiple values and the integrated language LINQ which is designed for querying collections in memory.

Chapter 5, Concurrency: Multithreading Parallel and Async Code, provides an introduction to writing efficient code that is high performing across different scenarios and how to avoid common pitfalls and mistakes.

Chapter 6, Entity Framework with SQL Server, introduces database design and storage using SQL and C# and provides an in-depth look at object-relational mapping using Entity Framework. The chapter also teaches common design patterns for working with databases.

Note

For those who are interested in learning the basics of databases and how to work with PostgreSQL, a reference chapter has been included in the GitHub repository of this book. You can access it at https://packt.link/oLQsL.

Chapter 7, Creating Modern Web Applications with ASP.NET, looks at how to write simple ASP.NET applications and how to use approaches such as server-side rendering and single-page applications to create web applications.

Chapter 8, Creating and Using Web API Clients, introduces APIs and teaches you how to access and consume Web APIs from ASP.NET code.

Chapter 9, Creating API Services, continues with the topic of APIs and teaches you how to create your API services for consumption, and how to secure it. The chapter also introduces you to the concept of microservices.

Note

There are also two bonus chapters (Chapter 10, Automated Testing, and Chapter 11, Production-Ready C#: From Development to Deployment) which you can find at https://packt.link/44j2X and https://packt.link/39qQA, respectively.

You can also find solutions for all activities in this Workshop online at https://packt.link/qclbF.

This book has some conventions set to arrange content efficiently. Read about them in the next section.

Conventions

Block of Code

In the book, a block of code is set as follows:

using System;
namespace Exercise1_01
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

In cases where inputting and executing some code gives an immediate output, this is shown as follows:

dotnet run
Hello World!
Good morning Mars!

Emphasis

Definitions, new terms, and important words are shown like this:

Multithreading is a form of concurrency whereby multiple threads are used to perform operations.

Technical Terms

Language commands within the body of the chapter are indicated in the following manner:

Here, the simplest Task constructor is passed an Action lambda statement, which is the actual target code that you want to execute. The target code writes the message Inside taskA to the console.

Added Information

Essential information is indicated in the following way:

Note

The term Factory is often used in software development to represent methods that help create objects.

Truncation

Long code snippets are truncated and the corresponding names of the code files on GitHub are placed at the top of the truncated code. Permalinks to the entire code are placed below the code snippet, as follows:

HashSetExamples.cs

using System;
using System.Collections.Generic;
namespace Chapter04.Examples
{
}

Before you dive into the power of the C# language, you will need to install the .NET runtime and the C# development and debugging tools.

Before You Begin

You can either install the full Visual Studio Integrated Development Environment (IDE), which offers a fully featured code editor (this is a costly license) or you can install Visual Studio Code (VS Code), Microsoft's lightweight cross-platform editor. The C# Workshop targets the VS Code editor as this does not require a license fee and works seamlessly across multiple platforms.