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: converts and behaves as in Go.
Supported with limits: the note says which.
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
int and uint are platform-width; integer overflow wraps and division by zero panics, as in Go. How · example
Complex numbers
complex64, complex128, real, imag; math/cmplx passes Go’s tests. Example
Strings and runes
UTF-8 bytes, as in Go: indexing reads bytes, range decodes runes. How · example
Constants, untyped constants, iota
Exact constant arithmetic, and Go’s literal spelling kept in the output. How · example
Arrays
Value semantics: assigning or passing an array copies it. How · example
Slices
Shared backing arrays, append growth, three-index slices, nil versus empty. At most about 2.1 billion elements (Known issues). How · example
Maps
Nil-map reads, comma-ok, delete, clear, randomized iteration order. How · example
Structs
Value types, == comparison, anonymous structs, and tags that reflect reads. How · example
Pointers
&x, new, pointers to fields, elements and pointers; a local whose address escapes moves to the heap. How · example
nil and zero values
Every type’s zero value, and a typed nil pointer inside an interface. How · example
Defined (named) types
Conversions and constant contexts as in Go. How · example
Type aliases
Including exported aliases used from another package. How
Shifts
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
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
Results become C# tuples, evaluated in Go’s order. How · example
Named results
Including results that a deferred closure reads and changes. Example
Function values and closures
Closures share captured variables, as in Go. How · example
append, copy, len, cap, make, new, delete, close, clear, min, max and the rest. How · example
Variadic functions
f(s...) passes the caller’s slice itself, as Go does: the function’s writes, appends within capacity and kept references reach s. Example
panic and recover
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
Receiver methods become C# extension methods. How · example
Pointer and value receivers
Go’s automatic & and * at the call site. How · example
No implements needed: source generators build the C# glue. One shape is refused by name: another package’s unexported interface method met only through an embedded struct (GO2CS2016, known issue). How · example
== on interface values compares dynamic type and value. Example
Struct embedding and promotion
Promoted fields and methods, through pointers, across several levels and packages. A promoted unexported method of another package that satisfies that package’s interface is refused in some shapes (GO2CS2016, known issue). How · example
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
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).
A generic function whose method-set constraint needs a shape witness the converter cannot place yet
A type argument or constraint from another package, a method value taken through the type parameter (f := x.M), or a value of the type parameter converted to a non-empty interface, under a non-self-referential method-set constraint, is refused with GO2CS2013, naming each site (Limitations).
A pointer type parameter beside methods (func F[T any, PT interface{ *T; M() }])
The pointer-method idiom from the Go type parameters proposal is refused with GO2CS2005 at each call site, whether the constraint is written inline, through a generic named constraint or through an embedded one. A pointer type argument under a constraint that holds comparable beside methods is refused the same way. Workaround: take the pointer as an interface value (func F(p Setter)) or the method as a function value (func F[T any](set func(*T, string))) (diagnostic codes).
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 · async twins
Goroutine stacks
Stacks do not grow: each goroutine reserves a large fixed stack, and recursion past it ends the process (Tuning).
runtime.GOMAXPROCS
Read and set; with the default threads it does not limit parallelism: GOMAXPROCS(1) does not run goroutines one at a time (Limitations). With async twins and GO2CS_MN=1 it sets how many goroutines run at once, as in Go (Async twins).
Deadlock detection
Go’s all goroutines are asleep report appears when every goroutine waits on a channel, a select, a WaitGroup, a Cond or an RWMutex and no timer is pending. Only nil-channel and select {} waits print their frames; a deadlock through a sync.Mutex, or in a cgo program, hangs. GO2CS_DEADLOCK=0 turns it off (Limitations).
The race detector (-race)
Validation runs without it (Limitations); converted code has no race detector.
encoding/json and text/template pass Go’s tests on it; StructOf, MakeFunc and the rest. How · example
runtime.Caller, Callers, FuncForPC
Go file and line, read from the program’s debug symbols. Optimized code can report an earlier line of the calling function: known issue. Example · FuncForPC
Garbage collection
.NET’s collector. GOGC and GOMEMLIMIT are read and reported, but the collector does not follow them (Limitations).
Finalizers, runtime.AddCleanup, weak
Run on .NET object lifetime: an object may not be collectable until the function that dropped it returns. Example
unsafe.Pointer and uintptr
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
Work, and a slice of one number type laid over another’s storage shares it, as in Go. A write through unsafe.StringData’s pointer into a string literal reaches every equal string (Limitations). Example
reflect under Native AOT
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
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)
Lists every goroutine and what it waits on, with frames for the calling goroutine only.
Profiling
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
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
Each package becomes a namespace and its own assembly. How · example
internal packages
Converted like any package; the standard library’s are.
Modules and third-party dependencies
-recurse=nuget converts a module and everything it imports (walkthrough). Some dependencies need a build tag (Limitations).
Build tags, GOOS, GOARCH
Files are selected as Go selects them; one conversion targets one operating system. Example
glibc, validated here. Ubuntu’s own .NET package has a known issue.
darwin/amd64, darwin/arm64
Packages ship for both chips, and the standard library is validated on both (roster). On Apple silicon the packages carry the arm64 build of the standard library, a few of whose members throw when called (Known issues); through 1.26.11.1 it was the amd64 build (Known issues).
linux/arm64
glibc, validated here. A few standard-library members throw when called (Known issues). Platforms
windows/arm64
Builds with a warning and runs the Windows build, whose architecture-specific choices follow amd64; not validated. Platforms
The syscall package on Windows, Linux and macOS, including syscall.NewCallback on Windows. Example · callback
cgo: calling C functions
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. Since 1.26.11.2, a void * into Go memory that holds no Go pointers converts too; C a package defines itself, in its preamble or its own C files, is compiled into a side library beside the bindings; C variables of a scalar or struct type are read and written in place; and C can call an //export back through a function pointer Go handed it (Limitations). Measured on linux/amd64, darwin/amd64, darwin/arm64 and windows/amd64 (Roadmap).
Calling .NET from Go source
The road runs one way: Go source cannot name a .NET API (Limitations).
cgo: unions, C++ and other languages, foreign-thread callbacks
Unions, flexible array members, a C variable of an array, pointer or union type, a package’s own C++, Objective-C or Fortran files, an //export C calls by name or on a thread the C library made, and a pointer into Go memory that holds Go pointers. Each is refused by name (Limitations, Roadmap). In go2cs 1.26.11.1, C a package defines itself, C variables, callbacks into Go and a void * into Go memory are refused too.
Hand-written assembly (.s files)
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
plugin.Open returns plugin: not implemented, as in a Go build without cgo.