从arraylist中检索数据 [英] Retrieve data from arraylist
本文介绍了从arraylist中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想从阵列中检索数据。
Hi all,
I want to retrieve data from array.
'Variable for assigning data
Structure StatementInfo
Dim strName As String
Dim strAccNo As String
Dim strOwnAdd1 As String
Dim strOwnAdd2 As String
Dim strOwnAdd3 As String
Dim strOwnAdd4 As String
Dim strMaster As ArrayList
End Structure
Public Structure Details
Dim strTarikh As String
Dim strStatus As String
Dim strNoRujukan As String
Dim strKod As String
Dim strKeterangan As String
Dim strDebit As String
Dim strKredit As String
Dim strBaki As String
End Structure
Public strDetails As Details
'Assign value to array (for example)
strName = "Micheal"
strAccNo = "46121212"
strOwnAdd1 = "Micheal"
strOwnAdd2 = "Micheal"
strOwnAdd3 = "Micheal"
strName = "Micheal"
strucStatementInfo.strMaster = New ArrayList
For i = 0 To (CInt(txtCount.Text) - 1)
With strDetails
.strTarikh = "01-JAN-2013"
.strStatus = "B"
.strNoRujukan = "20131004386" & i.ToString
.strKod = "1101" & i.ToString
.strKeterangan = "CUKAI TAKSIRAN"
.strDebit = "124.1" & i.ToString
.strKredit = "0"
.strBaki = "124.36"
End With
strucStatementInfo.strMaster.Add(strDetails)
Next
'Successfull to insert into arraylist
'But failed to view data where it only display the data from the last array
For i = 0 To (strucStatementInfo.strMaster.Count - 1)
With strucStatementInfo.strMaster(i)
strText1 = strDetails.strTarikh
strText2 = strDetails.strStatus
strText3 = strDetails.strNoRujukan
strText4 = strDetails.strKod
strText5 = strDetails.strKeterangan
strText6 = strDetails.strDebit
strText7 = strDetails.strKredit
strText8 = strDetails.strBaki
End With
Next
<pre>
任何人知道如何从arraylist中的结构中检索数据?
Anyone know how to retrieve data from structure within arraylist?
推荐答案
有两种方法:一种是将从ArrayList检索的对象显式地转换回Details结构:
There are two ways: one is to explicitly cast the object you retrieve from the ArrayList back to a Details structure:
Dim detail As Details = TryCast(strucStatementInfo.strMaster(i), Details)
If detail IsNot Nothing Then
With detail
...
End With
End If
但更好的方法不是完全使用ArrayList:改为使用通用List:
But the better way is not to use an ArrayList at all: use a generic List instead:
Dim myList As New List(Of Details)()
因为它只接受属于Details结构的对象,并且在你拿出它时不需要转换对象,因为系统已经知道它是什么。
缺乏咖啡馆feine引起的拼写错误 - OriginalGriff [/ edit]
Because it will only accept objects which are Details structures, and you don't need to cast the object when you take it out becuse the system already knows what it is.
[edit]Lack-of-caffeine induced spelling errors - OriginalGriff[/edit]
这篇关于从arraylist中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文