我正在创建一个管理来福乐系统的不和谐机器人。我需要机器人能够动态地创建抽奖条目的列表,因为抽奖是在我的raffle类中创建的(每个抽奖一个列表)。我可以使用一个二维数组来实现这一点,因为到目前为止,我已经对所有其他内容都使用了列表,并且我喜欢它们的易用性。在VB.net中使用列表来完成此操作的最佳方式是什么?到目前为止,我在互联网上看到的嵌套列表示例有点让我难以理解。
Private RaffleIDList As New List(Of Integer)
Private RaffleNameList As New List(Of String)
Private RaffleCountdownList As New List(Of Integer)
Private RaffleMinimumEntriesList As New List(Of Integer)
Private RaffleRewardTitleList As New List(Of String)
Private RaffleRewardLinkList As New List(Of String)
Private RaffleGoLiveList As New List(Of DateTime)
'TODO: Improve Entry storage to allow lists for each Raffle
Private RaffleEntries As New List(Of Discord.IUser)
Function addRaffle(ByVal RaffleName As String, ByVal RaffleCountdown As Integer, ByVal RaffleMinimumEntries As Integer, ByVal RaffleRewardTitle As String, ByVal RaffleRewardLink As String, ByVal RaffleGoLive As DateTime) As Integer
'Ensure all required perameters are provided and valid
If RaffleName <> Nothing Then
'Return RaffleID if creation is succesful
Dim newId As Integer = getNewRaffleID()
'Add Raffle
RaffleIDList.Add(newId)
RaffleNameList.Add(RaffleName)
RaffleCountdownList.Add(RaffleCountdown)
RaffleMinimumEntriesList.Add(RaffleMinimumEntries)
RaffleRewardTitleList.Add(RaffleRewardTitle)
RaffleRewardLinkList.Add(RaffleRewardLink)
RaffleGoLiveList.Add(RaffleGoLive)
Return newId
End If
'Return failure if not passed above.
Return -1
End Function提供的代码在我的Raffle类中,显示了我的Raffle变量和addRAffle()函数。目前,我只声明一个列表(RaffleEntries)来保存(Discord.Iuser的)条目,但我真正需要的是能够为每个活动抽奖拥有一个单独的条目列表。
发布于 2019-07-31 12:50:38
你似乎已经做错了。您不应该拥有所有这些单独的列表,而应该拥有自定义类型的单个列表。您应该定义一个Raffle类,它将具有ID、Name、Countdown、...和GoLive属性。它还会有一个List(Of Discord.IUser)类型的Entries属性。每次创建Raffle对象时,它都已经包含了内部列表,并且可以通过该属性进行访问。
例如。
Public Class Raffle
Public Property Id As Integer
Public Property Name As String
'...
Public Property GoLive As Date
Public ReadOnly Property Entries As New List(Of Discord.IUser)
End Class和示例用法:
Dim raffles As New List(Of Raffle)
Dim r As New Raffle With {.Id = 1,
.Name = "First",
.GoLive = Date.Today}
r.Entries.Add(entry1)
raffles.Add(r)https://stackoverflow.com/questions/57282905
复制相似问题