ArrayList用法疑问

Frewin 2006-06-30 06:00:34
Public Booklist As System.Collections.ArrayList
Public Structure BooklistStruct
Public BusinIndex As Integer
Public BookID As Integer
Public BookName As String
Public BookPrice As Decimal



Public Sub New(ByVal varBusinIndex As Integer, ByVal varBookID As Integer, ByVal varBookName As String, ByVal varBookPrice As Decimal)
BusinIndex = varBusinIndex
BookID = varBookID
BookName = varBookName
BookPrice = varBookPrice
End Sub
End Structure

Public Sub addlist()
If Booklist Is Nothing Then
Booklist = New ArrayList
End If
Booklist.Add(New BooklistStruct(1, 1, ".NET 2005", 120))
Booklist.Add(New BooklistStruct(1, 2, "Delphi5.0", 100))
Booklist.Add(New BooklistStruct(2, 1, ".NET 2005", 130))
Booklist.Add(New BooklistStruct(2, 2, "Delphi5.0", 110))
End Sub
'1)实现根据输入的BusinIndex得到所有对应的BooklistStruct
'即:如果输入BusinIndex=2 ,Return BooklistStruct.BookID = 1,BookName=".NET 2005",BookPrice=130
'BooklistStruct.BookID = 2,BookName="Delphi5.0",BookPrice=110
...全文
225 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
3tzjq 2006-07-01
  • 打赏
  • 举报
回复
如果BusinIndex是唯一的,就建议使用Hashtable,这样免去了遍历之苦!
觉得此数据结构更适合使用DataTable.
sanjie88 2006-06-30
  • 打赏
  • 举报
回复
'1)实现根据输入的BusinIndex得到所有对应的BooklistStruct
如果是这样的话,为什么不用hashtable呢
机器人 2006-06-30
  • 打赏
  • 举报
回复
楼上的不完全正确,我改一下:

Public Function Booklists(ByVal index As Integer) As ArrayList
Dim b As BooklistStruct
Dim findBookList As New ArrayList
For Each b In Booklist
If b.BusinIndex = index Then
findBookList.Add(b)
End If
Next
Return findBookList
End Function

泡沫游走 2006-06-30
  • 打赏
  • 举报
回复

Public Function Booklists(ByVal index As Integer) As BooklistStruct
Dim b As BooklistStruct
For Each b In Booklist
If b.BusinIndex = index Then
Return b
Exit Function
End If
Next
Return Nothing
End Function
amandag 2006-06-30
  • 打赏
  • 举报
回复
what are you going to do?

up
viena 2006-06-30
  • 打赏
  • 举报
回复
?

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧