Go feature support

Most of Go converts and behaves as it does in Go: slices, maps, pointers, closures, defer, interfaces, generics, goroutines, channels and select, reflection, and the whole standard library, which is validated against Go’s own tests. The tables below go feature by feature. Each note links to how the feature maps to C#, to a working example from the behavioral test suite, or, for a feature with limits, to the page that describes them.

Symbol Meaning
Supported Supported: converts and behaves as in Go.
Supported with limits Supported with limits: the note says which.
Not supported yet Not supported yet.

An example link opens a behavioral test: a Go program, its converted C#, and the output both must print. Limitations and Known issues have the detail behind every entry that is supported with limits or not supported yet.

Types and values

Feature Status Notes
Booleans, integers, floating point Supported int and uint are platform-width; integer overflow wraps and division by zero panics, as in Go. How · example
Complex numbers Supported complex64, complex128, real, imag; math/cmplx passes Go’s tests. Example
Strings and runes Supported UTF-8 bytes, as in Go: indexing reads bytes, range decodes runes. How · example
Constants, untyped constants, iota Supported Exact constant arithmetic, and Go’s literal spelling kept in the output. How · example
Arrays Supported Value semantics: assigning or passing an array copies it. How · example
Slices Supported Shared backing arrays, append growth, three-index slices, nil versus empty. How · example
Maps Supported Nil-map reads, comma-ok, delete, clear, randomized iteration order. How · example
Structs Supported Value types, == comparison, anonymous structs, and tags that reflect reads. How · example
Pointers Supported &x, new, pointers to fields, elements and pointers; a local whose address escapes moves to the heap. How · example
nil and zero values Supported Every type’s zero value, and a typed nil pointer inside an interface. How · example
Defined (named) types Supported Conversions and constant contexts as in Go. How · example
Type aliases Supported Including exported aliases used from another package. How
Shifts Supported with limits Go’s rules, including the panic on a negative count. One rare form, an untyped-constant left shift typed by a named integer, wraps an oversized count (Limitations). Example
The address of another package’s variable Supported with limits Real for a value-typed variable. For one whose type is a pointer or an interface it points at a copy (Known issues).

Functions and control flow

Feature Status Notes
Multiple results and comma-ok forms Supported Results become C# tuples, evaluated in Go’s order. How · example
Named results Supported Including results that a deferred closure reads and changes. Example
Function values and closures Supported Closures share captured variables, as in Go. How · example
Method values and method expressions Supported f := v.M and T.M. Example · example
defer Supported Last in, first out, with arguments evaluated at the defer statement. How · example
init functions and package initialization order Supported Go’s dependency order, across files. How · example
if, for, switch, fallthrough Supported How · example
for loop variables per iteration Supported Each iteration gets its own variable, as in Go. Example
range over slices, arrays, strings, maps, channels and integers Supported How · example · integers
range over functions, and iter Supported Range-over-func loops and iter.Pull; package iter passes Go’s tests. Example
Labels, labeled break/continue, goto Supported How · example
Built-in functions Supported append, copy, len, cap, make, new, delete, close, clear, min, max and the rest. How · example
Variadic functions Supported with limits f(s...) works. A function that keeps, returns or captures its ...T parameter, or appends or copies into it, works on a private copy of the caller’s slice (Limitations). Example
panic and recover Supported with limits Go panics and run-time errors (nil dereference, index out of range, divide by zero) recover as in Go. Other .NET exceptions run the deferred calls but recover() returns nil (Limitations). Example

Methods and interfaces

Feature Status Notes
Methods on any defined type Supported Receiver methods become C# extension methods. How · example
Pointer and value receivers Supported Go’s automatic & and * at the call site. How · example
Methods on a nil receiver Supported Example
Interfaces, satisfied structurally Supported No implements needed: source generators build the C# glue. How · example
Embedded and anonymous interfaces Supported Example · anonymous
Empty interface (any) Supported Including any as a map key. How · example
Interface comparison Supported == on interface values compares dynamic type and value. Example
Struct embedding and promotion Supported Promoted fields and methods, through pointers, across several levels and packages. How · example
Type assertions Supported Both the panicking form and comma-ok. Example
Type switches Supported How · example

Generics

Feature Status Notes
Generic functions Supported How · example
Generic types and their methods Supported Example
Constraints and type sets Supported Unions, ~T, comparable, and constraints with methods. How · example
Type inference Supported Example
Generic type aliases Supported with limits Converted, except an alias whose target is an anonymous struct or interface (Limitations). Example
A pointer element under a self-referential constraint whose method returns a collection of the element Not supported yet Walk[*Node] under Walk[N Tree[N]] with Children() []N is refused with GO2CS2002; the same code over a value element converts (Limitations). Two related pointer-element shapes are refused as GO2CS2005 and GO2CS2006 (diagnostic codes).

Concurrency

Feature Status Notes
Channels, buffered and unbuffered Supported How · example · buffered
close, and closed channels Supported Receive from a closed channel, panic on send, and blocked goroutines woken. Example · send
Nil channels Supported Block forever, and drop out of a select. Example
select Supported With default, and a random choice among ready cases. Example · fairness
sync, sync/atomic Supported Built on .NET primitives; both packages pass Go’s tests. Example
context, timers and tickers Supported context passes Go’s tests. Example
runtime.Gosched, Goexit, LockOSThread Supported Example
testing/synctest Supported Passes Go’s tests (roster).
Goroutines Supported with limits Go’s semantics, on real threads by default. Each live goroutine then holds an operating-system thread, so thousands at once are fine and hundreds of thousands are not; macOS and Linux each cap the count lower (Limitations, Known issues). How · example
Goroutine stacks Supported with limits Stacks do not grow: each goroutine reserves a large fixed stack, and recursion past it ends the process (Tuning).
runtime.GOMAXPROCS Supported with limits Read and set; with the default threads it does not limit parallelism: GOMAXPROCS(1) does not run goroutines one at a time (Limitations).
Deadlock detection Supported with limits Go’s all goroutines are asleep report, with its goroutine blocks, appears only when every goroutine waits on a nil channel or an empty select {}; any other deadlock hangs (Limitations).
The race detector (-race) Not supported yet Validation runs without it (Limitations); converted code has no race detector.

Memory and runtime

Feature Status Notes
unsafe.Sizeof, Alignof, Offsetof Supported Fold to Go’s numbers. Example
reflect Supported encoding/json and text/template pass Go’s tests on it; StructOf, MakeFunc and the rest. How · example
runtime.Caller, Callers, FuncForPC Supported Go file and line, read from the program’s debug symbols. Example · FuncForPC
Garbage collection Supported with limits .NET’s collector. GOGC and GOMEMLIMIT are read and reported, but the collector does not follow them (Limitations).
Finalizers, runtime.AddCleanup, weak Supported with limits Run on .NET object lifetime: an object may not be collectable until the function that dropped it returns. Example
unsafe.Pointer and uintptr Supported with limits Work over plain data. A pointer to anything .NET’s collector tracks (a string, slice, map, interface or pointer inside) gets a stand-in number, so tricks such as a hand-built slice header do not convert. How · example
unsafe.Slice, unsafe.String and friends Supported with limits Work, except that a slice of one number type laid over another’s storage is a copy (Limitations). Example
reflect under Native AOT Supported with limits A type built at run time (StructOf) needs the JIT, and a few shapes no compiled code names are refused by name, as a panic recover can catch (FAQ). Example
Panic output and exit status Supported with limits Go’s panic lines and exit status 2. The traceback is sometimes shorter than Go’s (Limitations). Example
Goroutine dumps (runtime.Stack for all goroutines) Supported with limits Lists every goroutine and what it waits on, with frames for the calling goroutine only.
Profiling Supported with limits Heap and allocation profiles and runtime/trace annotations work; a CPU profile has no samples, so profile with .NET’s tools. Example · trace
debug.ReadBuildInfo Supported with limits The module, its dependencies and the main build settings; no compiler, build-mode or vcs.* settings. Example

Packages, build and tests

Feature Status Notes
Packages and imports Supported Each package becomes a namespace and its own assembly. How · example
internal packages Supported Converted like any package; the standard library’s are.
Modules and third-party dependencies Supported -recurse=nuget converts a module and everything it imports (walkthrough). Some dependencies need a build tag (Limitations).
Build tags, GOOS, GOARCH Supported Files are selected as Go selects them; one conversion targets one operating system. Example
//go:embed Supported string, []byte and embed.FS. Example
The Go language version Supported Code must build with the Go release go2cs tracks (Requirements); a newer one is refused by name.
Go’s standard library Supported Converted in full and validated against Go’s own tests, package by package (roster).
Test functions, through -tests Supported Converts a package’s tests, runs them, and compares each verdict with go test (how).
//go:linkname Supported with limits A link to a function or variable with a C# body forwards to it; any other converts to a stub that fails when called. How · example
Native AOT, trimming, ReadyToRun Supported with limits All work. A Native AOT publish is slow and large (FAQ).
Examples, benchmarks and fuzz targets Not supported yet Not run yet (Roadmap).

Platforms

Target Status Notes
windows/amd64 Supported The standard library is validated here.
linux/amd64 Supported glibc, validated here. Ubuntu’s own .NET package has a known issue.
darwin/amd64, darwin/arm64 Supported with limits Packages ship for both chips, and the standard library is validated on both (roster). On Apple silicon the standard library is the amd64 build (Known issues).
linux/arm64 Supported with limits glibc, validated here. A few standard-library members throw when called (Known issues). Platforms
windows/arm64 Supported with limits Builds with a warning and runs the Windows build, whose architecture-specific choices follow amd64; not validated. Platforms
Other targets (wasm, the BSDs, 32-bit) Not supported yet Platforms

Interop

Feature Status Notes
Calling converted Go from C# Supported A converted package is an ordinary .NET library (Consuming converted Go). Example
System calls Supported The syscall package on Windows, Linux and macOS, including syscall.NewCallback on Windows. Example · callback
cgo: calling C functions Supported with limits Under go2cs -cgo, a package that calls C library functions converts and compiles, and loads its C library at run time. C types, typedefs and constants arrive through a C pseudo-package. Structs pass by value or by pointer. C.CString, C.GoString, C.GoBytes, C.malloc, C.free, a void * into C memory, and defer C.f(…) convert. Measured on linux/amd64, darwin/amd64, darwin/arm64 and windows/amd64 (Roadmap).
Calling .NET from Go source Not supported yet The road runs one way: Go source cannot name a .NET API (Limitations).
cgo: callbacks, C globals, unions, inline C Not supported yet Function pointers and callbacks into Go, C global variables, unions by value, flexible array members, a pointer into Go memory handed to C (an array or slice element, or unsafe.Pointer(&x)), and C code written inline in the Go file. Each is refused by name (Roadmap).
Hand-written assembly (.s files) Not supported yet Not translated: such a function converts to a stub that fails when called. Many libraries have a pure-Go build tag (Limitations). The standard library uses Go’s portable code and hand-written C# instead (how).
plugin Not supported yet plugin.Open returns plugin: not implemented, as in a Go build without cgo.