Enum Pairing and Searching C# Unity

Viewed 414

I am trying to pair an Enum to another. I have an Enum that has 35 different emote names like "angry","sad","happy"... The enum values are in a dropdown and I can search through them. So I want to create another enum that has values for the first enum like "smile" is ":)", "laugh" is ":D". So when I type ":D" in searchbar I want it to give me the laugh option in dropdown.

1 Answers

You could use Enumerable.Zip

Something like

var output 
    = names.Zip( // zip names
            emotes, // with the emotes
            (first, second) => new {first, second}) // create a two element object
        .ToDictionary(kv => kv.first, kv=> kv.second ); // turn that into a dictionary key-value pair

This will create a dictionary where you can use the emoji as a key and it'll return your word, or you can swap round the names and emotes for the oposite key-value.

Related