- Quick Start
- Create a New Project
- Show snippets using regions
- Create Sessions
- Verify your Project
- Passing Arguments
- Using Read-only Snippets
- Reference
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.
-
Open
Program.cs
from yourMyDocProject
project. -
Start a code region by placing
#region say_hello
on the line aboveConsole.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 } } }
-
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 ```
-
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 »