Samples and tutorials

The .NET documentation contains a set of samples and tutorials that teach you about .NET. This topic describes how to find, view, and download .NET Core, ASP.NET Core, and C# samples and tutorials. Find resources to learn the F# programming language on the F# Foundation's site. If you're interested in exploring C# using an online code editor, try these interactive tutorials. For instructions on how to view and download sample code, see the Viewing and downloading samples section.

.NET Core

Samples

Unit Testing in .NET Core using dotnet test

This guide shows you how to create an ASP.NET Core web app and associated unit tests. It starts by creating a simple web service app and then adds tests. It continues with creating more tests to guide implementing new features. The completed sample is available in the dotnet/docs repository on GitHub.

Tutorials

Writing .NET Core console apps using the CLI tools: A step-by-step guide

This guide shows you how to use the .NET Core CLI tooling to build cross-platform console apps. It starts with a basic console app and eventually spans multiple projects, including testing. You add features step-by-step, building your knowledge as you go. The completed sample is available in the dotnet/docs repository on GitHub.

Writing Libraries with Cross Platform Tools

This sample covers how to write libraries for .NET using cross-platform CLI tools. These tools provide an efficient and low-level experience that works across any supported operating system. The completed sample is available in the dotnet/docs repository on GitHub.

ASP.NET Core

See the ASP.NET Core tutorials. Many articles in the ASP.NET Core documentation have links to samples written for them.

C# language

Samples

Iterators

This sample demonstrates the syntax and features for creating and consuming C# iterators. The completed sample is available in the dotnet/docs repository on GitHub.

Indexers

This sample demonstrates the syntax and features for C# indexers. The completed sample is available in the dotnet/docs repository on GitHub.

Delegates and Events

This sample demonstrates the syntax and features for C# delegates and events. The completed sample is available in the dotnet/docs repository on GitHub. A second sample focused on events is also in the same repository.

Expression Trees

This sample demonstrates many of the problems that can be solved by using Expression Trees. The completed sample is available in the dotnet/docs repository on GitHub.

LINQ Samples

This series of samples demonstrate many of the features of Language Integrated Query (LINQ). The completed sample is available in the dotnet/docs repository on GitHub.

Tutorials

Console Application

This tutorial demonstrates Console I/O, the structure of a console app, and the basics of the task-based asynchronous programming model. The completed sample is available in the dotnet/docs repository on GitHub.

REST Client

This tutorial demonstrates web communications, JSON serialization, and object-oriented features of the C# language. The completed sample is available in the dotnet/docs repository on GitHub.

Working with LINQ

This tutorial demonstrates many of the features of LINQ and the language elements that support it. The completed sample is available in the dotnet/docs repository on GitHub.

Microservices hosted in Docker

This tutorial demonstrates building an ASP.NET Core microservice and hosting it in Docker. The completed sample is available in the dotnet/docs repository on GitHub.

Getting started with .NET Core on macOS using Visual Studio for Mac

This tutorial shows you how to build a simple .NET Core console app using Visual Studio for Mac.

Building a complete .NET Core solution on macOS using Visual Studio for Mac

This tutorial shows you how to build a complete .NET Core solution that includes a reusable library and unit testing.

Deploying to containers

Running ASP.NET MVC Applications in Windows Docker Containers

This tutorial demonstrates how to deploy an existing ASP.NET MVC app in a Windows Docker Container. The completed sample is available in the dotnet/docs repository on GitHub.

Running .NET Framework Console Applications in Windows Containers

This tutorial demonstrates how to deploy an existing console app in a Windows container. The completed sample is available in the dotnet/docs repository on GitHub.

Viewing and downloading samples

Many topics show source code and samples that are available for viewing or download from GitHub. To view a sample, just follow the sample link. To download the code, follow these instructions:

  1. Download the repository that contains the sample code by performing one of the following procedures:
    • Download a ZIP of the repository to your local system. Un-ZIP the compressed archive.
    • Fork the repository and clone the fork to your local system. Forking and cloning permits you to make contributions to the documentation by committing changes to your fork and then creating a pull request for the official docs repository. For more information, see the .NET Documentation Contributing Guide and the ASP.NET Docs Contributing Guide.
    • Clone the repository locally. If you clone a docs repository directly to your local system, you won't be able to make commits directly against the official repository, so you won't be able to make documentation contributions later. Use the fork and clone procedure previously described if you want to preserve the opportunity to contribute to the documentation later.
  2. Navigate within the repository's folders to the sample's location. The relative path to the sample's location appears in your browser's address bar when you follow the link to the sample.
  3. To run a sample, you have several options:
    • Use the dotnet CLI tools: In a console window, navigate to the sample's folder and use dotnet CLI commands.
    • Use Visual Studio or Visual Studio for Mac: Open the sample by selecting File > Open > Project/Solution from the menu bar, navigate to the sample project folder, and select the project file (.csproj or .fsproj).
    • Use Visual Studio Code: Open the sample by selecting File > Open Folder from the menu bar and selecting the sample's project folder.
    • Use a different IDE that supports .NET Core projects.