Magic commandsΒΆ

  1. %%CS

%%CS

The magic command wraps the C# code into a Python function the user can call.

%%CS cspower -i System
public static double cspower(double x, double y)
{
    if (y == 0) return 1.0 ;
    return System.Math.Pow(x,y) ;
}

To call it:

cspower(3.0, 3.0)

The magic command relies on create_cs_function and adds it to the notebook context. Dependencies are usually specified on the first line. However, it is quite inconvenient to have a very long first line so the first cell line of the cell will be seen as a continuation if they start by - like follows:

%%CS cspower
-i System
public static double cspower(double x, double y)
{
    if (y == 0) return 1.0 ;
    return System.Math.Pow(x,y) ;
}

(original entry : csmagics.py:docstring of csharpy.notebook.csmagics.CsMagics.CS, line 3)