使用值填充公共数组

时间:2015-10-13 13:35:29

标签: arrays vb.net

基本数组问题: 我已经声明了一个公共数组并用值初始化它。在另一个私有子中,我想用值填充该公共数组。最简单的方法是什么?

数组中的双变量也被声明为public。以下代码是在公共模块中创建和初始化的数组。在私有子中,我正在更改双变量(ch0LowLmt,ch1LowLmt等等)的值,现在我只想简单地用新值重新初始化数组。最简单的方法是什么?

Tinytest.add('Call a method that raise an exception', function (test) {
    test.throws(
        Joe.init, // That could be a way, but this fails
        "This is an exception"
    );

    test.throws(
        Joe.init(),
        "This is an exception"
    );
});

1 个答案:

答案 0 :(得分:0)

由于Doublevalue type,您需要以工作方式手动更改。

另一种方法是将double var封装在一个类中,该类可以放在数组中,因此它将是一个引用类型。

在这种情况下,您只需在您提到的私有函数中更新新的引用类型对象。它们也会在你的阵列中发生变化。

查看一个不错的解决方案here

Vb.Net中的代码示例:

Public Class MyObjectWithADouble
    Public Property Element() As Double
        Get
            Return m_Element
        End Get
        Set
            m_Element = Value
        End Set
    End Property
    Private m_Element As Double
    ' property is optional, but preferred.
End Class

Dim obj = New MyObjectWithADouble()
obj.Element = 5.0