Tips for moving between Go and C#

submited by
Style Pass
2024-07-05 13:30:07

Recently, I’ve implemented a Unicode tokenizer in in Go and in C#, and my career has been ~equally divided between those languages. Here are some tips moving between them.

In Go, properties and methods defined at the top level of a package have ~the same semantics as C#’s static. Go uses the unfortunate term “global” for this, but it’s better understood package-scoped, and static for callers.

In C#, there are reference types (classes) and value types (structs, primitives). In Go, there are only value types, and then one can choose to make a reference (pointer) to the value. You will do this if you want to the object to be mutable or to maintain state.

C# classes have constructor methods with their own semantics. In Go, one just writes a plain method that does the constructing. This is also true of getters and setters. Go doesn’t have them, just use plain methods.

C# allows several methods to have the same name but different parameters. Those unique signatures are enough to infer which of the same-named methods to call. This can make for a nice API for the caller.

Leave a Comment