Skip to content

Latest commit

 

History

History
65 lines (47 loc) · 1.9 KB

Regions.md

File metadata and controls

65 lines (47 loc) · 1.9 KB

Step-by-step tutorial: Show snippets using regions

Code documentation almost always features code snippets in isolation, like this:

Console.WriteLine(DateTime.Now);

The dotnet try tool provides a way to do this while also making the code sample interactive:

Console.WriteLine("Hello World!");

This is done using the --region option, which targets a C# code region. Let's try this in your project.

  1. Open Program.cs from your MyDocProject project.

  2. Start a code region by placing #region say_hello on the line above Console.WriteLine("Hello World!");. Then, place #endregion on the line after.

    Your Program.cs should look like this:

    using System;
    
    namespace HelloWorld
    {
        class Program
        {
            static void Main(string[] args)
            {
                #region say_hello
                Console.WriteLine("Hello World!");
                #endregion
            }
        }
    }
  3. In doc.md, modify your code fence, appending the --region option.

    # My code sample:
    
    ```cs --source-file ./MyConsoleApp/Program.cs --project ./MyConsoleApp/MyConsoleApp.csproj --region say_hello
    ```
  4. When you refresh your browser, your Try .NET editor should now only show a single line of code:

    Console.WriteLine("Hello World!");

NEXT: Create Sessions »