Thursday, January 12, 2017

Enums alternative in C#

While reading the following blog post(http://piotrgankiewicz.com/2017/01/09/async-http-api-and-service-bus/) I noticed this code snippet:

This code is taking advantage of the Expression-bodied function members in C# 6. And although this is just a static class with some readonly properties I found it aesthecially pleasing and it looks like a useful (and more flexible) alternative to enums.

If you look at the syntax you had to use before, it just feels more like a normal class instead of an enum construct…

An alternative approach would be using Getter-only auto-properties but it doesn’t feel the same as well…