Enum Extension Methods

Did you know you can create extension methods for enums?

public enum Suit { Diamonds, Hearts, Clubs, Spades }

public static class SuitExtensions
    public static string AsSymbol(this Suit suit) => suit switch
        Suit.Diamonds => "\u2666",
        Suit.Hearts => "\u2665",
        Suit.Clubs => "\u2663",
        Suit.Spades => "\u2660",
        _ => ""

You'll need the extra static class and I usually just pack the class and the enum in the same file. It feels like adding methods to your enum values. You can call the extension method directly on the enum value:


To see the output properly you'll need to have a terminal that properly undertstands unicode output like Windows Terminal.