- 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.csfrom yourMyDocProjectproject. -
Start a code region by placing
#region say_helloon the line aboveConsole.WriteLine("Hello World!");. Then, place#endregionon the line after.Your
Program.csshould 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--regionoption.# 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: Define Sessions »