Search code examples
c#visual-studio-2017

What does int[*] mean in C# under Visual studio 2017


We make use of a third party dll that exposes a method taking an out NetworkStream.Data[] parameter:

public void Read(int elementsCount, int timeOutInMs, out Data[] array, out bool timedOut)

We use it in our code by passing in a NetworkStream.Data (a datatype defined in said library) array, and it compiles fine under Visual Studio 2012.

However, when compiled under Visual Studio 2017, this generates a cast error:

Error CS1503 Argument 4: unable to cast 'out NetworkStream.Data[]' to 'out NetworkStream.Data[*]'

Decompilers such as DnSpy do indicate the same thing in the tooltip for the method, and in IL it shows the argumnt to be

[out] valuetype NetworkStream.Data[0...]& data

What does this NetworkStream.Data[*] or NetworkStream.Data[0...] mean and why does the cast fail in VS 2017?


Solution

  • It means that the array has one or more lower bounds that are not zero.

    For example, this code:

    Array test = Array.CreateInstance(typeof(int), new[] { 2 }, new[] { 2 });
    Console.WriteLine(test.GetType().FullName);
    

    Prints System.Int32[*].