title: Using Double.NaN in optional parameter on interface
body: <p>I have come across something confusing or potentially a bug in Visual Studio 2010 when defining an interface in my VB application: When defining an interface method with a default parameter of type Double, using the Double.NaN constant as the default value causes the code editor/intellisense/precompiler some issues.</p>
  
  <p>The following code underlines "INaNTest" and "INaNTest.DoSomething" claiming that 'DoSomething' cannot implement 'DoSomething' because there is no matching sub on interface 'INaNTest':</p>
  
  <pre><code>Public Class NaNTest
      Implements INaNTest
      Public Sub DoSomething(ByVal x As Double,
                             Optional ByVal a As Double = Double.NaN)
                             Implements INaNTest.DoSomething
      End Sub
  End Class
  
  Public Interface INaNTest
      Sub DoSomething(ByVal x As Double,
                      Optional ByVal a As Double = Double.NaN)
  End Interface
  </code></pre>
  
  <p>Removing the implementation and starting from:</p>
  
  <pre><code>Public Class NaNTest
      Implements INaNTest
  End Class
  
  Public Interface INaNTest
      Sub DoSomething(ByVal x As Double,
                      Optional ByVal a As Double = Double.NaN)
  End Interface
  </code></pre>
  
  <p>where now "NaNTest" is underlined (Class 'NaNTest' must ...), hitting the return key at the end of the line "Implements INaNTest" (i.e. automatically insert implementation) adds the implementation:</p>
  
  <pre><code>    Public Sub DoSomething(ByVal x As Double,
                             Optional ByVal a As Double = -1.#IND)
                             Implements INaNTest.DoSomething
  
      End Sub
  </code></pre>
  
  <p>in which the code editor then underlines '#' (Identifier expected.). Thus the code automatically added code that is not right.</p>
  
  <p>Alternatively now, starting with the original code above, using the Error Correction Options button on the underlined "INaNTest.DoSomething" and selecting 'Generate method stub for 'DoSomething' in 'INaNTest', the added method stub is:</p>
  
  <pre><code>    Sub DoSomething(ByVal x As Double,
                      Optional ByVal a As Double = NaN)
  </code></pre>
  
  <p>where now "NaN" has been divorced from the "Double." prefix and underlined ('NaN' is not declared. It may be inaccessible due to its protection level.) The code editor has inserted invalid code again.</p>
  
  <p>Is there a correct solution to using Double.NaN as the default value for a method as defined on an interface, in VB.net, or is there a fundamental reason why this is impossible?</p>
  
  <p>Many thanks,
  JCollins</p>