Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using <code>Func&lt;string&gt;</code> and <code>Action&lt;string&gt;</code> (obviously very different to <code>Action</code> and <code>Func&lt;string&gt;</code>) in the <code>ClassWithDelegateMethods</code> removes the ambiguity.</p> <p>The ambiguity also occurs between <code>Action</code> and <code>Func&lt;int&gt;</code>.</p> <p>I also get the ambiguity error with this:</p> <pre><code>class Program { static void Main(string[] args) { ClassWithSimpleMethods classWithSimpleMethods = new ClassWithSimpleMethods(); ClassWithDelegateMethods classWithDelegateMethods = new ClassWithDelegateMethods(); classWithDelegateMethods.Method(classWithSimpleMethods.GetOne); } } class ClassWithDelegateMethods { public void Method(Func&lt;int&gt; func) { /* do something */ } public void Method(Func&lt;string&gt; func) { /* do something */ } } class ClassWithSimpleMethods { public string GetString() { return ""; } public int GetOne() { return 1; } } </code></pre> <p>Further experimentation shows that when passing in a method group by its self, the return type is completely ignored when determining which overload to use.</p> <pre><code>class Program { static void Main(string[] args) { ClassWithSimpleMethods classWithSimpleMethods = new ClassWithSimpleMethods(); ClassWithDelegateMethods classWithDelegateMethods = new ClassWithDelegateMethods(); //The call is ambiguous between the following methods or properties: //'test.ClassWithDelegateMethods.Method(System.Func&lt;int,int&gt;)' //and 'test.ClassWithDelegateMethods.Method(test.ClassWithDelegateMethods.aDelegate)' classWithDelegateMethods.Method(classWithSimpleMethods.GetX); } } class ClassWithDelegateMethods { public delegate string aDelegate(int x); public void Method(Func&lt;int&gt; func) { /* do something */ } public void Method(Func&lt;string&gt; func) { /* do something */ } public void Method(Func&lt;int, int&gt; func) { /* do something */ } public void Method(Func&lt;string, string&gt; func) { /* do something */ } public void Method(aDelegate ad) { } } class ClassWithSimpleMethods { public string GetString() { return ""; } public int GetOne() { return 1; } public string GetX(int x) { return x.ToString(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload