简体   繁体   中英

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?

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[*] .

这是一个具有非默认下限的数组, 请参见有关如何处理此问题的文档

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM