什么集合obj可以为每个索引保存3个参数? [英] what collection obj can hold 3 parameters per index?

查看:53
本文介绍了什么集合obj可以为每个索引保存3个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我需要在数组类型集合对象中存储一些值,这些对象可以为每个索引保存3个或更多参数
。我查看了集合对象,

哈希表对象,并且不希望使用多维

数组。在VB.Net中是否有这样的对象?


Dim obj As someCollectionObj

obj.Add(" parmA1"," parmA2"," parmA3)

obj.Add(parmB1,parmB2,parmB3)

....


检索物品

s = obj.Item(" parmA1",1)

t = obj.Item(" parmA1",2)


或者,Hashtable可以包含哈希表吗?


谢谢,

Rich

Yes, I need to store some values in an array type collection object that can
hold 3 or more parameters per index. I have looked at the collection object,
hashtable object and would prefer not to hassel with a multi-dimensional
array. Is there such an object in VB.Net?

Dim obj As someCollectionObj
obj.Add("parmA1", "parmA2", "parmA3")
obj.Add("parmB1", "parmB2", "parmB3")
....

retrieve items
s = obj.Item("parmA1", 1)
t = obj.Item("parmA1", 2)

or, can a Hashtable contain a hashtable?

Thanks,
Rich

推荐答案

我尝试编写一个集合类型类,但它没有返回任何内容。

我需要做什么才能返回值?


Sub Form_Load(...)

dim x As new clsSubScr

dim i As Integer,str1 As String

x.MailSrv =" test1"

x.MailSrv =" test2"

x.Mailsrv =" test3"

对于i = 1到3

x.coIDx = i

str1 = x.Mailsrv ''< ---即使收集对象

包含

Console.Writeline(str1)''值'test1"," test2" ;,test3

下一页

Class clsSubScr

Dim colmailSrv作为新集合,colListNO作为新集合

Dim colID As New Collection

Public coIdx As Integer

Dim str1 As String


属性mailSrv()As String

获取

str1 = colmailSrv(coIdx)

结束获取

设置(ByVal Value As String)

colmailSrv.Add(Value)

结束集

结束财产


属性listNO()As String

获取

str1 = colListNO(coIdx)

结束获取

设置(ByVal值为字符串)

colListNO.Add(Value)

结束集

结束财产


属性listID()As String

获取

str1 = colID(coIdx)

结束获取

Set(By Val Value As String)

colID.Add(Value)

结束套装

结束物业


结束类

谢谢,

Rich
I tried writing a collection type class, but it does not return anything.
What do I need to do to it so that it returns the values?

Sub Form_Load(...)
dim x As New clsSubScr
dim i As Integer, str1 As String
x.MailSrv = "test1"
x.MailSrv = "test2"
x.Mailsrv = "test3"
For i = 1 To 3
x.coIDx = i
str1 = x.Mailsrv ''<---this gets nothing even though the collect object
contains
Console.Writeline(str1) '' the values "test1", "test2", "test3"
Next
Class clsSubScr
Dim colmailSrv As New Collection, colListNO As New Collection
Dim colID As New Collection
Public coIdx As Integer
Dim str1 As String

Property mailSrv() As String
Get
str1 = colmailSrv(coIdx)
End Get
Set(ByVal Value As String)
colmailSrv.Add(Value)
End Set
End Property

Property listNO() As String
Get
str1 = colListNO(coIdx)
End Get
Set(ByVal Value As String)
colListNO.Add(Value)
End Set
End Property

Property listID() As String
Get
str1 = colID(coIdx)
End Get
Set(ByVal Value As String)
colID.Add(Value)
End Set
End Property

End Class
Thanks,
Rich


为什么不建立一个用于保存参数的结构,然后将其添加到一个

哈希表?

公共结构项目

Dim ParamA2 As String

Dim ParamA3 As String


Public Sub New(a2 as String,a3 As String)

ParamA2 = a2

ParamA3 = a3

End Sub

结束结构


Dim obj作为新HashTable

obj.Add(" ; paramA1",New Item(" paramA2"," paramA3"))

obj.Add(" paramB1",New Item(" paramB2"," paramB3"))


s = obj(" paramA1")。ParamA2

t = obj(" paramA1")。ParamA3


是的,哈希表可以包含哈希表。

Why not make a structure for holding parameters and then add that to an
hashtable?

Public Structure Item
Dim ParamA2 As String
Dim ParamA3 As String

Public Sub New (a2 as String, a3 As String)
ParamA2 = a2
ParamA3 = a3
End Sub
End Structure

Dim obj As New HashTable

obj.Add("paramA1", New Item("paramA2", "paramA3"))
obj.Add("paramB1", New Item("paramB2", "paramB3"))

s = obj("paramA1").ParamA2
t = obj("paramA1").ParamA3

And yes, a hashtable can contain a hashtable.


谢谢。我会放手一搏。结构 - 是 - 比课堂容易。


" Chris Dunaway"写道:
Thanks. I will give this a go. Structure - yes - easier than a class.

"Chris Dunaway" wrote:
为什么不制作一个用于保存参数的结构然后将其添加到
哈希表?

公共结构项目
昏暗ParamA2 As String
Dim ParamA3 As String

Public Sub New(a2 as String,a3 As String)
ParamA2 = a2
ParamA3 = a3
结束Sub
结束结构

Dim obj As New HashTable

obj.Add(" paramA1",New Item(" paramA2"," paramA3")) )
obj.Add(paramB1,New Item(paramB2,paramB3))

s = obj(" paramA1")。ParamA2 t = obj(" paramA1")。ParamA3

是的,哈希表可以包含哈希表。
Why not make a structure for holding parameters and then add that to an
hashtable?

Public Structure Item
Dim ParamA2 As String
Dim ParamA3 As String

Public Sub New (a2 as String, a3 As String)
ParamA2 = a2
ParamA3 = a3
End Sub
End Structure

Dim obj As New HashTable

obj.Add("paramA1", New Item("paramA2", "paramA3"))
obj.Add("paramB1", New Item("paramB2", "paramB3"))

s = obj("paramA1").ParamA2
t = obj("paramA1").ParamA3

And yes, a hashtable can contain a hashtable.



这篇关于什么集合obj可以为每个索引保存3个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆