Gettings started

XSharper can be used without learning much about it, knowing only C#. Add <?_ before C# code and done:


Running the script

Start command line prompt and download XSharper:

With the script saved to hello.xsh:


XSharper can also run scripts directly from the command line but Windows command processor likes to intervene and interpret double quotes and < > signs. To overcome that, either prefix your C# code with cmd /c "xsharper /// <your-code>":


or use a backtick ` instead of doublequote in your code, and enclose the code into double quotes:


Experimenting with scripts

Instead of trying code snippets with notepad, it often more convenient to use a GUI editor
GUI editorGUI editor

Some more details

Under the hood, XSharper will add the needed boilerplate code before and after your code, wrap it into a function and produce something like below:


Inserting inside a function body has its drawbacks though: you can't add your own types. To define your own types, add curved braces before and after your code (and also a return statement), then add the types/enums/whatever is needed below:


Finally, if C# code needs command line parameters, it may take a bit of copy/paste


But, particularly for command line parsing, XSharper provides better ways than writing C# code by hand.