本文介绍了如何从列表(T)中检索相关项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前我学会了如何使用词典列表,这样我就可以创建一个项目了。后来,需求发生了变化,我不得不看看List(T)。现在我有一个Contact类,其中包含:firstName,lastName,phoneNumber和birthday。



我可以将这些字段添加到列表中,但我不知道如何在需要时获取所有相关信息。我需要的是,一旦列表中有多个记录,我该如何检索所有相关字段。



那么,我该怎么做才能找到所有这些属于一起的信息?我怎么知道这个名字与这个姓氏有关?



我希望这是有道理的。如果没有,请告诉我,我会再试一次。



感谢您的帮助。



我尝试了什么:



这是我目前使用的代码,只是为了加载,所以我可以看到它是有效的。



将此联系人视为新列表(联系人)()



'添加联系信息到列表。

thisContact.Add(New Contact()With {

.FirstName =Joe,

.LastName =Langley ,

。电话号码=2175443,

。生日= CDate(05/16/1954)})



For thisContact中的每个细节

MsgBox(名字:& detail.FirstName _

& Environment.NewLine&姓氏:& detail.LastName _

& Environment.NewLine _

& Environment.NewLine&电话号码:& detail.PhoneNumber _

&环境。新浪潮& birthDaty:& detail.Birthday)

下一步

解决方案

Hi, a few days ago I learned how to use a Dictionary list so I could create a project. Later, requirements changed and I had to look at List(of T). Right now I have a Contact class that contains: firstName, lastName, phoneNumber, and birthday.

I'm able to add these fields to the list, but I don't know how to get all the related information back when I need it. What I need is, once I have multiple records in the list, how do I retrieve all the related fields.

So, what do I do to find all this information that belong together? How do I know that this first name goes with this last name?

I hope this makes sense. If it doesn't, just let me know and I will try again.

Thanks for any help.

What I have tried:

Here's my current code that I've used just to load things up so I can see how it works.

Dim thisContact As New List(Of Contact)()

' Add Contact info to the list.
thisContact.Add(New Contact() With {
.FirstName = "Joe",
.LastName = "Langley",
.PhoneNumber = "2175443",
.Birthday = CDate("05/16/1954")})

For Each detail In thisContact
MsgBox("First Name: " & detail.FirstName _
& Environment.NewLine & "Last name: " & detail.LastName _
& Environment.NewLine _
& Environment.NewLine & "Phone Number: " & detail.PhoneNumber _
& Environment.NewLine & "birthDaty: " & detail.Birthday)
Next

解决方案


这篇关于如何从列表(T)中检索相关项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:33