在vb.net中动态创建结构名称
我想使用字符串创建动态结构名称,以下是我的结构:在vb.net中动态创建结构名称,vb.net,dynamic,structure,Vb.net,Dynamic,Structure,我想使用字符串创建动态结构名称,以下是我的结构: Structure foo dim lorem as string dim ipsum as string dim dolor as integer dim sit as integer End structure 论创造 dim bar as new foo 'Bar is temporary, it holds the information and then change its name [I know
Structure foo
dim lorem as string
dim ipsum as string
dim dolor as integer
dim sit as integer
End structure
论创造
dim bar as new foo 'Bar is temporary, it holds the information and then change its name [I know that's not working like that, imagine] (See below)
bar.lorem = "Random string here"
bar.ipsum = "But random doesn't exist, right ?"
bar.dolor = 42
bar.sit = 1337
bar.name = "Foobar_" & var 'integer/string/variable here (lets say var is "Cookie")
因此,当我想使用该结构时,我可以这样做:
msgbox("Secret cookie code =D >> " & callFunctionThatGetsStructureByName("Foobar_Cookie").sit.tostring)
我得到了Blahblah.sit->1337
这可能吗?我希望我的解释清楚。如果我能得到任何帮助,谢谢:听起来你想要的只是一个小问题 只需创建一个新词典:
Dim myDictionary = new Dictionary(Of String, foo)()
然后,您可以按键向其中添加项目:
dim bar as new foo 'Bar is temporary, it holds the information and then change its name [I know that's not working like that, imagine] (See below)
bar.lorem = "Random string here"
bar.ipsum = "But random doesn't exist, right ?"
bar.dolor = 42
bar.sit = 1337
myDictionary.Add("Foobar_" & var, bar)
然后,您可以稍后从字典中检索它,如下所示:
Dim retrieved = myDictionary("Foobar_Cookie")
听起来你只是想要一本关于键和结构的字典。我会去搜索,谢谢,如果我有消息,我会发布。这很聪明,很完美,正是我需要的,非常感谢;这是你的饼干;