Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just want to let you know this <em>is</em> a bug specific to C# (and @leppie I have confirmed it does fail with the standard csc.exe, not even in Visual Studio). Redundantly specifying a named argument <em>shouldn't</em> cause a change in behaviour at all.</p> <p>The bug has been reported at <a href="https://connect.microsoft.com/VisualStudio/feedback/details/678498">Microsoft Connect</a>.</p> <p>The equivalent VB works fine (because it does compile I added a little bit to confirm the runtime behaviour is as expected):</p> <pre class="lang-vb prettyprint-override"><code>Imports System Module Test Function F(Of T)(ByVal fn As Func(Of T)) As T Return fn() End Function Function Inc(ByRef i as Integer) As String i += 1 Return i.ToString End Function Sub Main() Dim s As String s = F(Of String)(Function()"Hello World.") console.writeline(s) s = F(Function()"Hello, World!") console.writeline(s) s = F(Of String)(fn:=Function()"hello world.") console.writeline(s) s = F(fn:=Function()"hello world") console.writeline(s) Dim i As Integer Dim func As Func(Of String) = Function()"hello world " &amp; Inc(i) s = F(Of string)(func) console.writeline(s) s = F(func) console.writeline(s) s = F(Of string)(fn:=func) console.writeline(s) s = F(fn:=func) console.writeline(s) End Sub End Module </code></pre> <p>Output:</p> <pre class="lang-none prettyprint-override"><code>Hello World. Hello, World! hello world. hello world hello world 1 hello world 2 hello world 3 hello world 4 </code></pre>
 

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