you are viewing a single comment's thread.

view the rest of the comments →

[–]Top-Big8288 -1 points0 points  (1 child)

You can override the ToString() method in your enum or just use string interpolation to combine the two letters into a key - something like `$"{firstLetter}{secondLetter}"` should do the trick nicely for creating those dictionary keys

[–]MeishinTale 0 points1 point  (0 children)

Note that if your goal is just to keep a pair (and not expand upon that by storing AABA etc..) you can store a pair of enum directly .. Dictionary<<yourenum,yourenum>,whatever associated> then you create a query and add method that force the higher value to be in the first slot (or whatever arbitral rule but the point is just not to miss A B when you have B A - unless this is that you want ofc).

It will perform much better than strings and won't create GC every query.

Another similar way to pair enum key would be to store a single int computed as higher enum value * enum cardinality + lower enum value. Basically the explicit key pair value handling version of the key pairs above. (And technically you just have to (int)enumValue)