title: Mixing Out and Named Parameters in C#: Why Does Out Parameter Need to be Named As Well?
body: <p><strong>Short Version</strong>: A named argument following an <code>out</code> argument gives a compiler error, but I cannot find any support for this behaviour in the language specification.</p>
  
  <p><strong>Long Version</strong>:</p>
  
  <p>I'm using the <code>Enum.TryParse&lt;TEnum&gt;</code> three parameter overload, but I would prefer to name the <code>ignoreCase</code> parameter to make my code clearer, a call like:</p>
  
  <pre><code>MyEnum res;
  b = Enum.TryParse&lt;MyEnum&gt;(inputString, true, out res);
  </code></pre>
  
  <p>leaves the meaning of the boolean unclear (unless this method is known<sup>1</sup>). Hence I would like to use:</p>
  
  <pre><code>b = Enum.TryParse&lt;MyEnum&gt;(inputString, out res, ignoreCase: true);
  </code></pre>
  
  <p>However the compiler reports this as an error:</p>
  
  <blockquote>
    <p>Named argument 'ignoreCase' specifies a parameter for which a positional argument has already been given</p>
  </blockquote>
  
  <p>and the IDE highlights the <code>ignoreCase</code> parameter. VS2010 targeting .NET 4, and VS11 Beta targeting either 4 or 4.5 all give the same result. In all cases naming the <code>out</code> parameter removes the error.</p>
  
  <pre><code>b = Enum.TryParse&lt;MyEnum&gt;(inputString, result: out res, ignoreCase: true);
  </code></pre>
  
  <p>I've tried this across a number of different methods (including avoiding generics)<sup>2</sup>, both from the framework and in my assembly: always the same result: an <code>out</code> parameter followed by a named parameter gives an error.</p>
  
  <p>I can see no reason for this error, and &sect;7.5.1 <em>Argument Lists</em> of the <em>C# Language Specification: Version 4.0</em> does not seem to provide any reason why an <code>out</code> followed by a named parameter should give an error. The text of the error seems to support an interpretation as a bug: there is no positional argument which could be a valid match for <code>ignoreCase</code>.</p>
  
  <p>Is my reading of the specification wrong? Or is this a compiler bug?</p>
  
  <p><strong><em>C# 7.2 Update</em></strong></p>
  
  <p>This restriction on all named arguments have to follow positional arguments when calling was lifted with C# 7.2.</p>
  
  <p>See <a href="https://docs.microsoft.com/en-gb/dotnet/csharp/whats-new/csharp-7-2#non-trailing-named-arguments" rel="nofollow noreferrer">https://docs.microsoft.com/en-gb/dotnet/csharp/whats-new/csharp-7-2#non-trailing-named-arguments</a>.</p>
  
  <hr>
  
  <p><sup>1</sup> Hence the advice in the Framework Design Guidelines to prefer <code>enum</code> parameters.</p>
  
  <p><sup>2</sup> Eg: given:</p>
  
  <pre><code>private static void TestMethod(int one, float two, out string three) {
    three = "3333";
  }
  </code></pre>
  
  <p>this this call also gives the same error on the named parameter unless the <code>out</code> parameter is also named:</p>
  
  <pre><code>TestMethod(1, out aString, two: 1.0f);
  </code></pre>