1

我在整个代码中多次使用以下结构将一组数据传递给函数:

Public Structure MyStruct
    Dim ResourceID As String
    Dim RSRCName As String
    Dim CommercialType As String
    Dim ParticipantName As String
    Dim ASReserveZone As String
    Dim SCADAStatusQuality As String
    Dim SCADAStatus As String
    Dim SCADAMWQuality As String
    Dim ManualDispatchReason As String

    Dim RegUpQual As Boolean
    Dim RegDownQual As Boolean
    Dim SuppQual As Boolean
    Dim SpinQual As Boolean
    Dim UseEmergencyLimits As Boolean
    Dim FollowLastDispatch As Boolean

    Dim ASOfferCurveDict As HybridDictionary

    Dim XIC As Integer
    Dim PriceBased As Integer
    Dim PNodeID As Integer
    Dim Committed As Integer
    Dim CommitmentStatus As Integer
    Dim ManualDispatch As Integer
    Dim LastApprdNumOfIntervalsToMax As Integer

    Dim MWCurve() As Double
    Dim EnergyOfferCurve() As Double
    Dim PlannedMW As Double
    Dim SCADAMW As Double
    Dim InitialOnHours As Double
    Dim LastApprdDispatchMW As Double
    Dim TotalRampedCRDeployMW As Double
End Structure

Dim Struct as MyStruct

我可以Struct = Nothing用来重置数据,但我宁愿遍历结构并将所有数值设置为999999999. 知道怎么做吗?

4

1 回答 1

3

您可以通过反射来做到这一点,但我不一定会推荐它。我宁愿在结构中添加一个ClearorReset方法,将所有值设置为其默认值。另一种选择是在声明字段时设置默认值:

Public Structure MyStruct
    ' ...
    Dim XIC As Integer = 999999999
    Dim PriceBased As Integer = 999999999
    Dim PNodeID As Integer = 999999999
    ' ...
End Structure

然后,要将变量重置为所有默认值,只需执行以下操作:

myVariable = New MyStruct()

我还应该提一下,除非出于某种原因它确实需要成为一个结构,否则您应该将其更改为一个类。一直在堆栈上传递的数据非常多。

于 2013-02-15T15:13:27.483 回答