VB的对象ByRef字典 [英] VB dictionary of Objects ByRef

查看:107
本文介绍了VB的对象ByRef字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个Dim Dict As New Dictionary(Of String, Object),它将我的字符串指向特定的COM对象类,即Dict.Add("NODES",Visum.Net.Nodes) 我在字典中大约有20个键,每个键都指向COM对象中的不同类.

I want to create a Dim Dict As New Dictionary(Of String, Object) which would point my strings to specific COM Object classes, i.e. Dict.Add("NODES",Visum.Net.Nodes) I'd have around 20 keys in dictionary, each pointing to a different class within COM object.

基本上可以,但是恐怕它很重(有20个大类实例的字典)并且不是必需的-我将整个对象传递给dict,而我实际上只需要一种指针(ByRef ).

Basically it works, but I'm afraid it's very heavy (dict of 20 instances of big classes) and not neccessary - I'm passing whole object to a dict, while I really need just kind of pointer (ByRef).

还有更聪明的方法吗?

PS.我为什么要这么做?因为我要放入字典中的所有对象都具有通用方法.这样,我就可以呼叫:Dict("Nodes").ItemByKey(13),然后再呼叫Dict("Links").ItemByKey(13),等等.

PS. Why I do it? Because all objects which I'd put inside the dictionary have common methods. This way I'd be able to call i.e. : Dict("Nodes").ItemByKey(13), and then Dict("Links").ItemByKey(13), etc.

先谢谢了 拉法尔

推荐答案

我认为您存在误解.您已经已经传递并存储对对象的引用.这就是VB.NET的工作方式. (如果这是您的背景,则也是对象处理的VB6).带有对象类型的ByVal vs ByRef参数不会创建对象的副本,它只是表明您调用的方法是否可以有效地将您传递的对象与另一个对象交换出去.

I think you are under a misconception. You are already passing, and storing, a reference to your objects. That is the way VB.NET works. (It is also the VB6 dealt with objects, if that is your background). ByVal vs ByRef parameters with object types doesn't create copies of your objects, it just indicates if the method you called could, effectively, swap out your passed object with another.

这篇关于VB的对象ByRef字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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