{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[this doc on github](https://github.com/dotnet/interactive/tree/master/samples/notebooks/csharp/Docs)\n", "\n", "# Importing packages, libraries, and scripts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can load packages into a .NET notebook from NuGet using the following syntax:\n", "\n", "```csharp\n", "#r \"nuget:[,]\"\n", "```\n", "\n", "If you don't provide an explicit package version, the latest available non-preview version will be loaded.\n", "\n", "Here's an example:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" } }, "outputs": [], "source": [ "#r \"nuget:System.Reactive.Linq, 4.1.5\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that the package is loaded, we can add some `using` statements and write some code." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" } }, "outputs": [], "source": [ "using System.Reactive;\n", "using System.Reactive.Linq;\n", "using System.Reactive.Concurrency;\n", "\n", "var output = display(\"Counting...\");\n", "\n", "var sub = Observable\n", " .Interval(TimeSpan.FromSeconds(.5), CurrentThreadScheduler.Instance) \n", " .Take(10) \n", " .Subscribe(i => output.Update(i));" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to load an assembly that's already on disk, you can do so using this syntax:\n", "\n", "```csharp\n", "#r \"\"\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can load a C# script (typically a `.csx` file) into the notebook using this syntax:\n", "\n", "```csharp\n", "#load \"\"\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" } }, "outputs": [], "source": [ "#load \"something.csx\"" ] } ], "metadata": { "kernelspec": { "display_name": ".NET (C#)", "language": "C#", "name": ".net-csharp" }, "language_info": { "file_extension": ".cs", "mimetype": "text/x-csharp", "name": "C#", "pygments_lexer": "csharp", "version": "8.0" } }, "nbformat": 4, "nbformat_minor": 4 }