我尝试在一个类下编写“公共属性流(NumCommodities - 1)As Double”,但显然它需要额外的编码。
所以我需要这个属性,因为我需要根据这段代码跟踪值:
For t As Integer = 0 To MyProblem.Arcs.Count-1
For k = 0 To MyProblem.NumCommodities-1
Dim i As Integer = MyProblem.Arcs(t).Tail
Dim j As Integer = MyProblem.Arcs(t).Head
Dim akey As String = "x(" & i & "," & j & "," & k & ")“
Dim aid As Integer = solver.GetIndexFromKey(akey)
MyProblem.Arcs(t).Flow(k) = solver.GetValue(aid).ToDouble
Next
Next
OBS:我已经在MyProblem Class
下声明了这个Public Class MyProblem
Public NumCommodities
答案 0 :(得分:1)
您无法使用可变大小声明和数组。相反,你必须声明然后初始化它。
Public Property Flow As Double() = New Double(NumCommodities - 1) {}
请注意,如果NumCommodities - 1
为否定或者NumCommodities
尚未实例化,则会失败。
由于您的问题没有提供对该问题的大量见解,您可能还在尝试声明访问数组项的属性。以下是如何实现这样的事情:
Private _Flow As Double() = New Double() {}
Public Property Flow(ByVal NumCommodities As Int32) As Double
Get
Return _Flow(NumCommodities - 1)
End Get
Set(value As Double)
_Flow(NumCommodities - 1) = value
End Set
End Property