System.Double [*]是什么意思 [英] What does System.Double[*] mean

查看:445
本文介绍了System.Double [*]是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个gem是在我们反编译的一些interop代码中创建的。我们不知道如何创建这个数组的实例,也不知道它是什么类型的数组。

This gem was created in some interop code which we decompiled. We can't figure out how to create an instance of this array, nor what type of array it is.

查看 Type.GetElementType 给我,它是一个类型 Double 的数组,但我们不能弄清楚它是如何不同于 System。 Double []

Looking at Type.GetElementType gives me that it is an array of type Double, but we can't figure out how it is different from System.Double[].

推荐答案

这是一个典型的互操作问题,自动化服务器。这会将数组暴露为 SafeArray ,CLR会自动将它们编组为.NET数组对象,并按照安全数组描述符中的指定维护其结构。

This is a typical interop problem, the array was created in a COM Automation server. Which exposes the array as a SafeArray, the CLR automatically marshals them to a .NET array object and maintains its structure as specified in the safe array descriptor.

一个System.Double []数组是一个非常特殊的数组在CLR中,它是一个向量数组,其第一个元素在索引0.这些类型的数组在CLR中进行了大量优化。

A System.Double[] array is a very specific kind of array in the CLR, it is a "vector array" which has its first element at index 0. These kind of arrays are heavily optimized in the CLR.

你得到的数组的麻烦是它有一个维度,如一个向量数组,但没有其第一个元素在索引0.通常如果你与Visual Basic或FoxPro中编写的代码互操作。这样的代码通常喜欢在索引1开始数组。但是可以是任何

The trouble with the array you got is that it has one dimension, like a vector array, but does not have its first element at index 0. Common if you interop with code written in Visual Basic or FoxPro for example. Such code often likes to start the array at index 1. Could be anything however.

C#没有语法糖访问这样的数组,你不能使用[]运算符索引数组。你必须使用Array类的成员,ploddingly。所以:

C# does not have syntax sugar to access such an array, you cannot use the [] operator to index the array. You have to use the members of the Array class, ploddingly. So:


  • Array.GetLowerBound(0)告诉您从哪里开始索引数组

  • Array .GetUpperBound(0)告诉你要走多远

  • 用Array.GetValue(index)从数组中读取一个元素

可能更容易复制数组:

public static double[] ConvertDoubleArray(Array arr) {
    if (arr.Rank != 1) throw new ArgumentException();
    var retval = new double[arr.GetLength(0)];
    for (int ix = arr.GetLowerBound(0); ix <= arr.GetUpperBound(0); ++ix)
        retval[ix - arr.GetLowerBound(0)] = (double)arr.GetValue(ix);
    return retval;
}

这篇关于System.Double [*]是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆