title: Best way to refactor if statement method
body: <p>I currently have  a method that I'm hard coding the value that needs to be validate in the if statement and then I'm   running  the method that match the name I'm hardcoding.
  Here is my code </p>
  
  <pre><code>  public Class Name 
     public static Dictionary&lt;string, ValueMap&gt; Name1= new Dictionary&lt;string, ValueMap&gt;
       public static Dictionary&lt;string, ValueMap&gt; Name2= new Dictionary&lt;string, ValueMap&gt;
  
    public Class compare
   public string Test (string sample, string Name)
              {
  
                  if (sample == "Name1")
                  {
  
                      var results = MethodName (sample, Name.Name1);//call method name Name1
  
                      return "";
                  }
                  if (sample == "Name2")
                  {
                      var results = MethodName (sample, Name.Name2);  //call method name Name2  
  
                      return "";
                  }
                 if (sample == "Name3")
                  {
                      var results = MethodName (sample, Name.Name3);    //call method name Name3
  
                      return "";
                  }
  
                  else
                  {
                      return ""; ;
                  }
  
              }
  </code></pre>
  
  <p>I don't want to add an if statement every time I need to add a different method inside my MethodName or hardcode the values inside my if statement so I was wondering if there is a way I  can just look for the method inside the compare class that match the string sample and pass this  method to my var results = MethodName (sample, Name.Name3);    </p>
  
  <p>Example something like this </p>
  
  <pre><code> public Class Name 
     public static Dictionary&lt;string, ValueMap&gt; Name1= new Dictionary&lt;string, ValueMap&gt;
       public static Dictionary&lt;string, ValueMap&gt; Name2= new Dictionary&lt;string, ValueMap&gt;
  
       public Class Test
    string sample = Name1
           public string Test (string sample, string Name, Name name)
                      {
  
                              var results = MethodName (sample, Name1 -pass the method inside the compare class  that match the name inside the sample string );
  
                              return "";
                          }
  
                          else
                          {
                              return sample name was not found ; ;
                          }
  </code></pre>