C# (Wasm)
C# is a high-level, general-purpose, object-oriented programming language developed by Microsoft.
In LiveCodes, C# runs in the browser using Blazor WebAssembly with a WebAssembly-based .NET runtime.
Usage
Demo:
Communication with JavaScript
The C# code runs in the context of the result page. A few helper properties and methods are available in the browser global livecodes.csharp
object:
livecodes.csharp.input
: The initial standard input passed to the C# code.livecodes.csharp.loaded
: A promise that resolves when the C# environment (Blazor WebAssembly) is fully loaded. Other helpers should be used after this promise resolves.livecodes.csharp.output
: The standard output from the C# code execution.livecodes.csharp.run
: A function that runs the C# code with new input. This function takes a string as input and returns a promise that resolves with an object containing theoutput
,error
, andexitCode
properties.
Example:
Language Info
Name
csharp-wasm
Aliases / Extensions
cs
, csharp
, wasm.cs
, cs-wasm
Editor
script
Compiler
Blazor WebAssembly with .NET WebAssembly runtime.
Version
.NET 9.0
Code Formatting
using Prettier
Live Reload
By default, new code changes are sent to the result page for re-evaluation without a full page reload, avoiding the need to reinitialize the Blazor environment. This behavior can be disabled by adding the code comment // __livecodes_reload__
to the C# code, which forces a full page reload.
This comment can be added in the hiddenContent
property of the editor for embedded playgrounds.
Example Usage
using System;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello, LiveCodes C#!");
}
}
Starter Template
https://livecodes.io/?template=csharp-wasm