Gettings started

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

<?_
	Console.WriteLine("Hello, world!");
?>

Running the script

Start command line prompt and download XSharper:

start https://xsharper.com/xsharper.exe

With the script saved to hello.xsh:

C:\>xsharper hello.xsh
Hello, world!

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>":

C:\>cmd /c "xsharper /// Console.WriteLine("Hello, World")"
Hello, world!

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

C:\>xsharper /// "Console.WriteLine(`Hello, World`)"
Hello, world!

Experimenting with scripts

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

C:\>xsharper #/editor hello.xsh

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:

using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;
using System.Globalization;
using XS=XSharper.Core;
using System.Linq; // Only if compiled on a machine with .NET 3.5
using System.Xml.Linq; // Only if compiled on a machine with .NET 3.5

class RandomName
{
...
    public object MethodName() {
        // Your code goes here
       Console.WriteLine("Hello, world!");
       // Your code ends

       return null;
    }
}

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:

<?_
	{
		for (int i=0;i<10;++i)
			Console.WriteLine(new MyClass(i));
		return 0;
	}

	class MyClass { 
		int _x;
		public MyClass(int x) { _x=x;}
		public override string ToString() { return "MyClass("+_x+")"; }
	}
?>

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

<xsharper switchPrefixes=""><param name="arg" last="true" count="multiple" /><?_
	string[] args=c.GetStrArray("arg");
	
        /// your code begins
	Console.WriteLine("There are {0} commandline parameters specified:",args.Length);
	foreach (string a in args)
		Console.WriteLine(" "+a);		

?></xsharper>

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