Problem in implementing my own switch class
<p>I am trying to implement a custom switch case just for fun..</p>

<p>The approach is that I have created a class that inherits a dictionary object</p>

<pre><code>public class MySwitch&lt;T&gt; : Dictionary&lt;string, Func&lt;T&gt;&gt; 
    {
        public T Execute(string key)
        {
            if (this.ContainsKey(key)) return this[key]();
            else return default(T);
        } 
    }
</code></pre>

<p>And I am using as under</p>

<pre><code> new MySwitch&lt;int&gt;
    {
    { "case 1",  ()=&gt; MessageBox.Show("From1") },
    { "case 2..10",  ()=&gt;MessageBox.Show("From 2 to 10") },               
    }.Execute("case 2..10");
</code></pre>

<p>But if I specify <strong>"case 2"</strong> it gives a default value as the key is not in the dictionary.</p>

<p>The whole purpose of making <strong>"case 2..10 "</strong> is that if the user enters anything between <strong>case 2 to case 10</strong>, it will execute the same value.</p>

<p>Could anyone please help me in solving this?</p>

<p>Thanks</p>
