地图哈希表
问题描述:
对象引用我想一个对象,而不是对象值的参考用,当我去取回“HEADERS_PATH”的值的哈希表地图哈希表
configMapping.Add("HEADERS_PATH", Me.headers_path)
这种方式映射我就可以分配一个值Me.headers_path
有点像“&”经营者使用C
答
我假设Me.headers_path是一个System.String。因为System.String是不可变的,你想要的不能实现。但是您可以添加额外的间接级别来实现类似的行为。
计算机科学中的所有问题都可以通过另一个级别的 来间接解决。 巴特勒·兰普森
样品在C#(请善待编辑到VB后来删除此评论):
public class Holder<T> {
public T Value { get; set; }
}
...
Holder<String> headerPath = new Holder<String>() { Value = "this is a test" };
configMapping.Add("HEADERS_PATH", headerPath);
...
((Holder<String>)configMapping["HEADERS_PATH"]).Value = "this is a new test";
// headerPath.Value == "this is a new test"
答
化妆headers_path是礼(带套)
答
这似乎是一个字典,这在NET 2.0你可以定义为字典,如果你想要更新的引用总是字符串,或者字典(不推荐),如果你想获得任意的引用。
如果您需要替换字典中的值,您可以定义自己的类并提供一些帮助器方法以使其更容易。
答
我不完全确定你想要做什么。假设smink是正确的,那么这里是他的代码的VB翻译。对不起,我不能编辑它,我不认为我有足够的代表。
public class Holder(Of T)
public Value as T
end class
...
Dim headerPath as new Holder(Of String)
headerPath.Value = "this is a test"
configMapping.Add("HEADERS_PATH", headerPath)
...
Directcast(configMapping["HEADERS_PATH"]),Holder(Of String)).Value = "this is a new test"
'headerPath.Value now equals "this is a new test"
@marcj - 你需要逃避你的答案尖括号,所以用& LT;对于<和>为>。再次抱歉,我不能只为你编辑你的帖子。