如何取出list中的对象?

essenza 2009-09-24 11:29:30
以下为测试代码:

Dim listVillage As New List(Of Village)(200)

Dim newVillage As New Village
newVillage.ID = "123456"
newVillage.Name = "测试城市"
listVillage.Add(newVillage)


newVillage.ID = "654321"
newVillage.Name = "测试城市"
listVillage.Add(newVillage)

newVillage.ID = "654321"
newVillage.Name = "测试城市"
listVillage.Add(newVillage)

newVillage.ID = "654321"
newVillage.Name = "测试城市"
listVillage.Add(newVillage)

MsgBox(listVillage.Count)



For i As Integer = 1 To listVillage.Count
Me.TextBox1.AppendText(listVillage.Item(i - 1).ToString)

Next



我现在要TextBox1输出listVillage中的对象newVillage,应该如何做?

...全文
703 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xie_yanke 2009-09-24
  • 打赏
  • 举报
回复

For Each vill As Village In listVillage
Me.TextBox1.AppendText(vill.ID)
Next
essenza 2009-09-24
  • 打赏
  • 举报
回复
谢谢楼上的几位朋友 我这样取过,但是提示: vill.ID 未将对象引用设置到对象的实例

Dim vill As New Village

For Each vill In listVillage
Me.TextBox1.AppendText(vill.ID)
Next
simonezhlx 2009-09-24
  • 打赏
  • 举报
回复

foreach( Village tempV in listVillage )
{//tempV is the member of ListVillage
Me.TextBox1.AppendText( tempV.Name )
}

vb.net 代码?
woaipanda 2009-09-24
  • 打赏
  • 举报
回复
foreach

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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