This notebook demonstrates the features of the C# kernel for Jupyter Notebook. The C# Kernel plugin is using Roslyn as a backend to implement C# scripting.
The kernel is using C# scripting which is a little different than using C# with Visual Studio. We can define variables and print out their values or evaluate expressions.
In [1]:
int someInteger = 14323456;
someInteger
Out[1]:
In [2]:
double someDouble = 22.0/7;
someDouble
Out[2]:
It is also possible to evaluate expressions and print it out.
In [3]:
(1233+7)/32
Out[3]:
Console output also can be used to print out values.
In [4]:
var z = 12451;
Console.WriteLine($"The result is {z}.");
Here is an array and a list definition
In [5]:
var l = new int[] {1, 2, 3, 5, 7};
l
Out[5]:
In [6]:
var li = new List<int>() {1, 2, 3, 4, 5};
li
Out[6]:
It is also possible define methods and then call them later
In [7]:
int Add(int x, int y) { return x+y; }
Add(12,13)
Out[7]:
In [8]:
public class Person
{
public string FirstName { get; set;}
public string LastName { get; set; }
public int Age {get; set; }
};
List<Person> persons = new List<Person> {
new Person {FirstName = "John", LastName = "Doe", Age = 35},
new Person {FirstName = "Jane", LastName = "Doe", Age = 26},
};
persons.AsTable()
Out[8]:
It is also possible to select the columns to display.
In [9]:
persons.AsTable(new List<string> {"FirstName", "Age"})
Out[9]:
In [10]:
"f(x)".AsMath()
Out[10]:
In [11]:
"x=\\frac{1+y}{1+2z^2}".AsMath()
Out[11]:
In [12]:
var htmlContent = "<div style=\"background-color: #007fff; font-weight: bold;\">Would you like some toast?</div>";
htmlContent.AsHtml()
Out[12]:
Or embedding video...
In [15]:
var video = "<video width=\"480\" controls poster=\"https://archive.org/download/WebmVp8Vorbis/webmvp8.gif\" >"
+ "<source src=\"https://archive.org/download/WebmVp8Vorbis/webmvp8.webm\" type=\"video/webm\">"
+ "<source src=\"https://archive.org/download/WebmVp8Vorbis/webmvp8_512kb.mp4\" type=\"video/mp4\">"
+ "<source src=\"https://archive.org/download/WebmVp8Vorbis/webmvp8.ogv\" type=\"video/ogg\">"
+ "Your browser doesn't support HTML5 video tag."
+ "</video>";
video.AsHtml()
Out[15]:
In [3]:
#load "XPlot.Plotly.csx"
new int[,] data = {{1, 20, 30}, {20, 1, 60}, {30, 60 ,1}};
data
Out[3]:
In [1]:
Graph.Heatmap h = new Graph.Heatmap();
h.z = new int[,] { { 1, 20, 30 }, { 20, 1, 60 }, { 30, 60, 1 } };
var chart = Chart.Plot(h);
chart.WithLayout(new Layout.Layout() { title = "Heatmap example!" });
chart.WithHeight(500);
chart.WithWidth(700);
string html = chart.GetInlineHtml();
html.AsHtml()
Out[1]:
This notebook loosely based on the demo notebook from the IFsharp Kernel. Big kudos for the F# community for putting such a cool kernel together.