title: Cannot implicit convert a type
body: <p>I am running into a road block when I am trying to do some testing on delegate. My goal is to create instances of <code>MyStates</code> class that have the ability to call some predefined functions that I defined in <code>MyFunctions</code> class. In the class, I have a dictionary that will refer the functions by name and have a function that retrieve the address of the function and put it in <code>MyState</code> instance so that I could refer it at run time. The idea appears to be simple but the compiler is not happy about it. I think I may have an idea of what is wrong but I am not sure how to get rid of the compiler error. Please advise how to fix this compiler error.</p>
  
  <p><code>MyFunctions</code> class is defined as below:</p>
  
  <pre><code>public sealed class MyFunctions
  {
      public delegate int myFunction(object o);
      private static Dictionary&lt;string, myFunction&gt; funcRouter 
       = new Dictionary&lt;string, myFunction&gt;();
      #region Singleton
      private static readonly MyFunctions _functionInstance = new MyFunctions();
      static MyFunctions()
      {
  
      }
      private MyFunctions()
      {
          funcRouter.Add("Test2", Test2);
      }
      public static MyFunctions functionInstance
      {
          get
          {
              return _functionInstance;
          }
      }
      #endregion
  
      #region Definition and implementation of all the functions
      public int Test2(object o)
      {
          System.Diagnostics.Debug.WriteLine("Testing 2, object received {0}", (int)o);
          return 112;
      }
      #endregion
  
      public myFunction Get(string s)
      {
          return (myFunction)funcRouter[s];
      }
  
  }
  </code></pre>
  
  <p><code>MyStates</code> class is defined below:</p>
  
  <pre><code>public delegate int myFunction(object o);
  public class MyState
  {
      private int _ID;
      private myFunction _func;
  
      public myFunction func
      {
          get { return _func; }
      }
      public int ID
      {
          get { return _ID; }
      }
      public MyState(int myID, myFunction f = null)
      {
          _ID = myID;
          _func = f;
      }
  
  }
  </code></pre>
  
  <p>My main program:</p>
  
  <pre><code>public delegate int myFunction(object o);
  class Program
  {
  
      static void Main(string[] args)
      {
          myFunction f = null;
          //f = MyFunctions.functionInstance.Test2;
          f = MyFunctions.functionInstance.Get("Test2");
          MyState s = new MyState(123,f);
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>Note: The code above will generate the compiling error. However, if I use the statement</p>
  
  <pre><code>f = MyFunctions.functionInstance.Test2;
  </code></pre>
  
  <p>The program will compile fine and execute correctly. I think the issue resides in the use of dictionary to retrieve the address of the function. It is possible to possible to do that in C++, I would think C# should allow me to do the same thing. I just did not do it correctly. </p>
  
  <p>Please advise.</p>