title: How to call overloaded methods having optional parameters without ambiguity for compiler?
body: <p>I have a static function in a class with two overloads. Both the overloads are quite the same with the exception of one or two parameters. <code>string body</code> is the only necessary parameter in my function which you can see, rest are optional parameters. But parameters <code>object y</code> and <code>int x</code> shouldn't come together. So i had to write two overloads as below.  I provide a sample code:</p>
  
  <pre><code>    public static void Foo(string body, string caption = "", int x = 0)
      {
          //leave it to me
      }
  
      public static void Foo(string body, string caption = "", object y = null)
      {
          //leave it to me
      }
  </code></pre>
  
  <p>Now when I want to call this static function from other classes, since <code>string body</code> is the only required parameter, I try to write at times:</p>
  
  <pre><code>ClassABC.Foo("hi there");
  </code></pre>
  
  <p>Which gives me this: <code>The call is ambiguous between the following methods or properties</code>. I know why this happens, and what ideally the solution is. But I need to know if anything else could be done in C# to tackle this.</p>
  
  <p>Obviously, the compiler is confused as to choose which function to go for, but I wouldnt mind the compiler going for any considering both are the same without <code>int x</code> and <code>object y</code>. Three questions basically:</p>
  
  <ol>
  <li><p>Is there anyway to tell the compiler "take any" (almost impossible task, but still let me know)?</p></li>
  <li><p>If not, is there anyway I can create a single function to handle both cases? Something like this:</p>
  
  <pre><code>public static void Foo(string body, string caption = "", int x = 0 || object y = null) // the user should be able to pass only either of them!
  {
      //again, I can handle this no matter what
  }
  </code></pre></li>
  <li><p>Any other workarounds to solve this?</p></li>
  </ol>
  
  <p>EDIT: </p>
  
  <ol>
  <li><p>I can not rename the two functions.</p></li>
  <li><p>I can not create more overloads. It's not just these combinations possible. I should be able to write <code>Foo(string body, int x)</code> etc. So goes. Its virtually impossible to handle all conditions if parameters are more than say, 10!. In short, optional parameters are a must.</p></li>
  </ol>