如何在变量中设置Type? [英] How do I set the Type in a variable?

查看:65
本文介绍了如何在变量中设置Type?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何设置变量的类型?


例如:


Dim myhash as hastable

''我想将myhash中的Type设置为String或Integer甚至我自己的

自定义结构。


公共结构ContactUser

公共名字为字符串

公共中间名为字符串

......

结束结构


Dim tmpuser as new ContactUser

tmpuser.firstname =" John"

tmpuser .middlename =" D"

myhash.add(1,tmpuser)

解决方案

我可能错了,但我不要以为你能做到这一点。


但你可以创建自己的自定义哈希表类


Class MyCustomHashTable

继承HashTable


并重载属性以仅接受您所需的类类型
想要并返回该类。


这样的东西 - 虽然语法可能有点偏离


公共重载函数项(索引为整数)clsMyObjectType

返回ctype(list.items (索引),clsMyObjectType)

结束功能


这应该做你想要的,只需要很少的努力..


HTH,


Shane

"谢尔比" < SH **** @ itsupport.com.sg>在消息中写道

新闻:Oc ************** @ TK2MSFTNGP10.phx.gbl ...


如何设置变量的类型?

例如:

昏暗的myhash为hastable
''我想设置类型在myhash中作为String或Integer甚至是我自己的
自定义结构。

公共结构ContactUser
公共名字为字符串
公共中间名为字符串
.. ....
结束结构

Dim tmpuser as new ContactUser
tmpuser.firstname =" John"
tmpuser.middlename =" D"
myhash.add(1,tmpuser)



谢尔比,


你为什么选择没有回答我以前的回答,我说你可以做这个作为对象的
这是一个哈希表,把对象作为一个

arraylist我给你了在样本中使它变得如同简单?


Cor
如何设置变量的类型?

例如:

将myhash视为hastable
''我想设置在myhash中键入String或Integer甚至我自己的
自定义结构。

公共结构ContactUser
公共名字为字符串
公共中间名为字符串
......
结束结构

Dim tmpuser as new ContactUser
tmpuser.firstname =" John"
tmpuser.middlename =" D"
myhash.add(1,tmpuser)



嗨Cor,

呵呵?对不起,我不能找到你。


谢尔比

Cor Ligthert <无********** @ planet.nl>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...

谢谢,

为什么你没回答我之前的回答,我说你可以把
作为一个对象做什么,把对象当作一个
arraylist做什么是哈希表我在样本中给你的东西让它变得简单易行?

我如何设置变量的类型?

例如:

Dim myhash as hastable
''我想将myhash中的Type设置为String或Integer,甚至是我自己的
自定义Structure。 />
公共结构ContactUser
公共名字为字符串
公共中间名为字符串
......
结束结构

昏暗tmpuser as new ContactUser
tmpuser.firstname =" John"
tmpuser.middlename =" D"
myhash.add(1,tmpuser)




Hi,

how do I set the Type of a variable?

For example:

Dim myhash as hastable
'' I want to set the Type in myhash as String or Integer or even my own
custom Structure.

Public Structure ContactUser
Public firstname as string
Public middlename as string
......
End Structure

Dim tmpuser as new ContactUser
tmpuser.firstname = "John"
tmpuser.middlename = "D"
myhash.add (1,tmpuser)

解决方案

I may be wrong but I don''t really think you can do that.

But you could create your own custom hashtable class

Class MyCustomHashTable
Inherits HashTable

and overload the properties to only accept the type of class you are
wanting and return that class.

something like this--although syntax is probably a little off

public overloads function Items(index as integer) clsMyObjectType
return ctype(list.items(index),clsMyObjectType)
end function

This should do what you are wanting and require minimal effort..

HTH,

Shane
"Shelby" <sh****@itsupport.com.sg> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...

Hi,

how do I set the Type of a variable?

For example:

Dim myhash as hastable
'' I want to set the Type in myhash as String or Integer or even my own
custom Structure.

Public Structure ContactUser
Public firstname as string
Public middlename as string
......
End Structure

Dim tmpuser as new ContactUser
tmpuser.firstname = "John"
tmpuser.middlename = "D"
myhash.add (1,tmpuser)



Hi Shelby,

Why did you not answer on my previous answer where I said that you could do
this as an object, what is a hashtable else by holding the objects as an
arraylist which I gave you in the sample to make it as simple as posible?

Cor

how do I set the Type of a variable?

For example:

Dim myhash as hastable
'' I want to set the Type in myhash as String or Integer or even my own
custom Structure.

Public Structure ContactUser
Public firstname as string
Public middlename as string
......
End Structure

Dim tmpuser as new ContactUser
tmpuser.firstname = "John"
tmpuser.middlename = "D"
myhash.add (1,tmpuser)



Hi Cor,
huh? I''m sorry I don''t get you.

Shelby
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

Hi Shelby,

Why did you not answer on my previous answer where I said that you could do this as an object, what is a hashtable else by holding the objects as an
arraylist which I gave you in the sample to make it as simple as posible?

Cor

how do I set the Type of a variable?

For example:

Dim myhash as hastable
'' I want to set the Type in myhash as String or Integer or even my own
custom Structure.

Public Structure ContactUser
Public firstname as string
Public middlename as string
......
End Structure

Dim tmpuser as new ContactUser
tmpuser.firstname = "John"
tmpuser.middlename = "D"
myhash.add (1,tmpuser)




这篇关于如何在变量中设置Type?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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