DEV Community 👩‍💻👨‍💻

Kenichiro Nakamura
Kenichiro Nakamura

Posted on

Time to learn C# with Notebook in VS Code

Jupyter Notebook is popular platform to write and execute your code. However, not many C# developer use it as we have Visual Studio as our preferred IDE.

However, according to Introducing the Jupyter Extension for VS Code article, VS Code start supporting Jupyter Notebook more and more these days. So it's time to try C# on Jupyter Notebook.

.NET Interactive Notebooks

.NET Interactive Notebooks is an extension for VS Code, and it's easy to start using with 3 steps.

1. Install Visual Studio Code Insiders as it's preview feature at the moment. By the time you read this article, it would be included in normal VS Code though.

Alt Text

2. Install .NET Core SDK, which I believe all C# developer already have. The official page says to install .NET Core 3.1.

3. Install .NET Interactive Notebooks extension.

Alt Text

Just restart VS code to complete the installation.

Create your first notebook

Now you're ready to use it. Go to command palette and select "Create new blank notebook"

Alt Text

It may take a bit of time for initial notebook creation, so just wait until you see new notebook. Once it's ready, you see the notebook like below.

Alt Text

Type your code and execute by either click arrow icon or Shift+Enter.

Alt Text

Of course you can define class and use it.

Alt Text

.NET 5?

.NET 5 GA this week! Yay! But the extension supports .NET Core 3.1 at the moment. Let's wait until it support .NET 5. Check GitHub issue for more detail. I cannot wait to try Record type in notebook :)

Other than C#?

Yes, the extension supports various other dotnet related languages.

Alt Text

For example, you can write and execute PowerShell as well :)

Alt Text

Reference

dotnet/interactive
notebook samples for C#

Top comments (5)

Collapse
 
shaijut profile image
Shaiju T

Nice 😄, Thanks for sharing.

Collapse
 
hemanth22 profile image
Hemanth B

It's very nice.
But i have installed dotnet sdk 5 and dotnet sdk3.1, from commandline is it possible to install dotnet notebook by switching to dotnet 3.1

Collapse
 
kenakamu profile image
Kenichiro Nakamura Author

I don't have trouble using it with both version installed. Any issue you are facing?

Collapse
 
hemanth22 profile image
Hemanth B • Edited on

I am not able to install dotnet using below command using powershell.

dotnet tool install --global Microsoft.dotnet-interactive

i am getting below error still even through extension is installed.

Command '.NET Interactive: Create new blank notebook' resulted in an error (command 'dotnet-interactive.newNotebook' not found)

Thread Thread
 
kenakamu profile image
Kenichiro Nakamura Author

hm.. can you try --fx-version to specify 3.1?

🌚 Browsing with dark mode makes you a better developer by a factor of exactly 40.

It's a scientific fact.