Question

According to Common Language Specification, overload resolution for methods that have array parameters is based on the fact that they are arrays and on their element type. So the following code should be compliant (which it is) because Double()() is an array of arrays, where as Double() is an array of doubles.

<CLSCompliant(True)> _
Public Class VBTest

  Public Sub ArrayTest(value As Double())
  End Sub

  Public Sub ArrayTest(value As Double()())
  End Sub

End Class

However, with same code in C#, I get a warning on the 2nd ArrayTest method:

"Overloaded method 'CSTest.ArrayTest(double[][])' differing only by unnamed array types is not CLS-compliant"

[CLSCompliant(true)]
public class CSTest
  {
    public void ArrayTest(double[] value){}
    public void ArrayTest(double[][] value){}
  }

If I'm understanding this CLS rule correctly, does C# treat jagged arrays differently from VB? Or is this a bug in the C# compiler? I'm running VS2010 targeting .NET Framework 4.0 in both cases.

Was it helpful?

Solution

This is a documented bug in the C# compiler. It is mentioned in the MSDN article about CLS-Compliant code:

Note

Jagged arrays — that is, arrays of arrays — are CLS-compliant. In the .NET Framework version 1.0, the C# compiler mistakenly reports that they are not.

I checked it for 4.5, still not fixed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top