如何在 Class 下的 VB.NET 中编码此 "Public Property Flow(NumCommodities - 1) As Double"?
How do I code this "Public Property Flow(NumCommodities - 1) As Double" in a VB.NET under a Class?
我正在尝试在 class 下对这个 "Public Property Flow(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:我已经在我的问题下声明了这个 Class
Public Class MyProblem
Public NumCommodities
您不能声明大小可变的数组。相反,您必须声明然后初始化它。
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
我正在尝试在 class 下对这个 "Public Property Flow(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:我已经在我的问题下声明了这个 Class
Public Class MyProblem
Public NumCommodities
您不能声明大小可变的数组。相反,您必须声明然后初始化它。
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