Skip to content

18 · Modules

C# · .NET

Embed typed C# functions, CLR objects, callbacks and asynchronous calls. Prepare with the .NET tooling and retain the matching runtime when deploying.

On this page

Run locally with the matching plugin and runtime. These examples do not run in the browser playground.

C# / .NET.

14-extern-csharp.zolo
// expected:

// 42

// 9223372036854775807

// Zolo

// 11

// 12

// 42

// 40

// 42


use plugin dotnet::{csharp}
use std::async::Promise

extern csharp fn add(a: int, b: int) -> int {
    return a + b;
}

extern csharp fn exact(value: int) -> int {
    return value;
}

extern csharp fn counter(start: int) -> fn() -> int {
    var value = start;
    return () => System.Threading.Interlocked.Increment(ref value);
}

extern csharp fn apply(value: int, transform: fn(int) -> int) -> int {
    return transform(value);
}

extern csharp async fn twice(value: int) -> int {
    await System.Threading.Tasks.Task.Delay(10);
    return value * 2;
}

print(add(20, 22))
print(exact(9223372036854775807))

let original = "  Zolo  "
let clean: str = extern csharp {
    return original.Trim();
}
print(clean)

let next = counter(10)
print(next())
print(next())

print(apply(20) { |value| add(value, 22) })

let results = await Promise.all([twice(20), twice(21)])
print(results[0])
print(results[1])

Requires the Zolo CLI/host — open in the playground or run locally.

Preparation and deployment

Source-free packaging can retain prepared foreign artifacts, but does not remove runtime or platform dependencies. VM, native and LLVM hosting are covered; foreign bindings reject unsupported WebAssembly targets. The recent provider acceptance covers Windows x64. Python acceptance specifically covers CPython 3.12; other platforms need their own verification.

Reference overview

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br