Refactoring from if-else-if to Dictionary I have come across the following piece of code

 if (Region.Current == Region.EU)
    {
      return RegionalPriceLN;
    }
    else if (Region.Current == Region.NY)
    {
      return RegionalPriceNY;
    }
    else if (Region.Current == Region.HK)
    {
      return RegionalPriceHK;
    }
    else if (Region.Current == Region.TK)
    {
      return RegionalPriceTK;
    }

    return null;


And want to refactor it to use a Dictionary. Was thinking of something like below:

return Map.TryGetValue(Region.Current, out func) ? func() : null;


And the dictionary being initialized like this:

 Map = new Dictionary&lt;Region, Func&lt;double?&gt;&gt;
                             {
                               {Region.EU, () =&gt; RegionalPriceLN},
                               {Region.NY, () =&gt; RegionalPriceNY},
                               {Region.HK, () =&gt; RegionalPriceHK},
                               {Region.TK, () =&gt; RegionalPriceTK}
                             };


Another approach, to optimize memory usage would be to hold a static dictionary instead of an instance one:

private static readonly Dictionary&lt;Region, Func&lt;TickingBasket, double?&gt;&gt; Map = new Dictionary&lt;Region, Func&lt;TickingBasket,double?&gt;&gt;
                             {
                               {Region.EU, t_ =&gt; t_.RegionalPriceLN},
                               {Region.NY, t_ =&gt; t_.RegionalPriceNY},
                               {Region.HK, t_ =&gt; t_.RegionalPriceHK},
                               {Region.TK, t_ =&gt; t_.RegionalPriceTK}
                             };


This would require for us to pass "this" to the delegate:

return Map.TryGetValue(Region.Current, out func) ? func(this) : null;


Can you think of a more elegant way to do this? 

Regards.

UPDATE: Region is a reference type.
Second option is definitely a preferred way over first one. Also you may consider a switch statement.

UPDATE. Since Region is a class then the only good way to avoid long if...else is the mapping like in your second variant

First option that you proposed (Map = new Dictionary&lt;Region, Func&lt;double?&gt;&gt;) requires the construction of Dictionary each time the method is executed. It is a waste of resources and time, and for this case even the if..else..if..else statements don't look that ugly :).

Second option (static Dictionary with fixed mappings) is a traditional way to branch the logic for your case. Moreover in certain cases C# compiler will compile the switch statement into static Dictionary to run lookups.