Jay Norwood:

Using enums, despite their problems, if often better than strings.


    static Suits[] suits =  [
                {Suit.spades, 1, 6, SuitShort.spd},
                {Suit.hearts, 4, 10, SuitShort.hrt},
                {Suit.diamonds, 4, 10, SuitShort.dmd},
                {Suit.clubs, 10, 16, SuitShort.clb}
        ];

    foreach (immutable member;  suits)


In some cases you can also use with() to avoid struct/enum name repetitions (unfortunately it creates a scope, so if you define an immutable variable inside it, it will be invisible and destroyed once the with() scope ends. This reduces the usefulness of with()).


    with (Suit) with (SuitShort)
    {
        static Suits[] suits = [
            {spades,    1,  6, spd},
            {hearts,    4, 10, hrt},
            {diamonds,  4, 10, dmd},
            {clubs,    10, 16, clb}
        ];

        foreach (immutable member;  suits)
        ...


Bye,
bearophile

Reply via email to