# Implementing Enumerations In Go

DevFeed: [Implementing Enumerations In Go](<https://devfeed.tech/articles/implementing-enumerations-in-go-22228.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/09/implementing-enumerations-in-golang.html>)

Published: 2023-09-21T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [C#](<https://devfeed.tech/topics/csharp.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [code](<https://devfeed.tech/tags/code.md>), [coding](<https://devfeed.tech/tags/coding.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [enumeration](<https://devfeed.tech/tags/enumeration.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [implement](<https://devfeed.tech/tags/implement.md>), [readability](<https://devfeed.tech/tags/readability.md>)

## AI overview

A tutorial on implementing enumeration-like types in Go. It compares Go's lack of native enumerations with C# enumerations and presents a struct-based pattern intended to provide compiler protection and improve type safety for a defined set of string values.

## Source excerpt

Introduction Prior to coding in Go, I was writing software in C#. In C# enumerations can be declared and the associated type can be used in functions and as fields in a struct. The compiler won't allow a value of the enumerated type to be passed or set that doesn't belong to the defined set. This is something that I have missed since coding in Go. Go doesn't have enumerations and it can be a problem at times when you want type safety for a well-defined set of values. A common way people try to have enumerations in Go really doesn't work for me because of the way constants behave. That being said, I have developed a pattern that gets me as close as possible to what I had in C# though it's not perfect and I will explain.