本文介绍了VB.NET中的多维关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我vb.net中多维关联数组的示例吗?需要数组来容纳人们的姓名,年龄和其他一些设置.希望能够使用Dictionary来使用People.Add.
Hi can someone show me an example of a multidimensional associative array in vb.net. Need array to hold peoples name, there age and a few other settings. Want to be able to use a Dictionary to use People.Add.
谢谢
-马克
推荐答案
请考虑OOP.您应该使用一个类将属性彼此关联.示例:
Think OOP. You should use a class to associate the properties with each other. Example:
Class Person
Private _name as String
Private _age as Integer
Public ReadOnly Property Name
Get
Return _name
End Get
End Property
Public ReadOnly Property Age
Get
Return _age
End Get
End Property
Public Sub New(name As String, age as Integer)
_name = name
_age = age
End Sub
End Class
现在您可以将人们放在字典中:
Now you can put the people in a dictionary:
Dim people As New Dictionary(Of String, Person)()
people.Add("John", new Person("John", 42))
people.Add("Jane", new Person("Jane", 12))
这篇关于VB.NET中的多维关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!