在 Visual Studio 2017 下的 C# 中 int[*] 是什么意思 [英] What does int[*] mean in C# under Visual studio 2017
问题描述
我们使用第三方 dll,该 dll 公开了取出 NetworkStream.Data[] 参数的方法:
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)
我们通过传入一个 NetworkStream.Data(在上述库中定义的数据类型)数组在我们的代码中使用它,并且它在 Visual Studio 2012 下编译得很好.
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.
但是,在 Visual Studio 2017 下编译时,这会生成强制转换错误:
However, when compiled under Visual Studio 2017, this generates a cast error:
错误 CS1503 参数 4:无法将输出 NetworkStream.Data[]"转换为输出 NetworkStream.Data[*]"
Error CS1503 Argument 4: unable to cast 'out NetworkStream.Data[]' to 'out NetworkStream.Data[*]'
DnSpy 之类的反编译器确实在该方法的工具提示中指示了相同的内容,并且在 IL 中它显示了该参数
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
这个 NetworkStream.Data[*] 或 NetworkStream.Data[0...] 是什么意思,为什么转换在 VS 2017 中失败?
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.
例如这段代码:
Array test = Array.CreateInstance(typeof(int), new[] { 2 }, new[] { 2 });
Console.WriteLine(test.GetType().FullName);
打印System.Int32[*]
.
这篇关于在 Visual Studio 2017 下的 C# 中 int[*] 是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!