Wug*_*Wug 10 vb6 tuples built-in
我正在将一些C#代码移植到VB6,因为遗留应用程序.我需要存储一对配对列表.我不需要进行关联查找,我只需要能够存储成对的项目.
我正在移植的片段如下所示:
List<KeyValuePair<string, string>> listOfPairs;
Run Code Online (Sandbox Code Playgroud)
如果我将它移植到C++,我会使用这样的东西:
std::list<std::pair<string, string> > someList;
Run Code Online (Sandbox Code Playgroud)
如果这是python,我只使用元组列表.
someList.append( ("herp", "derp") )
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种图书馆类型,但如果有必要,我会满足于其他的东西.我试图成为LAZY而不必编写cYetAnotherTinyUtilityClass.cls来获得此功能,或者回到经常被滥用的字符串操作.
我试过谷歌搜索,但VB6并没有真正在线记录,很多有什么,很好的挑战.如果你见过BigResource,你会明白我的意思.
Variants的集合可以非常灵活,除非你真的打败它们,否则性能不是问题:
Private Sub SomeCode()
Dim Pair As Variant
Dim ListOfPairs As Collection
Set ListOfPairs = New Collection
With ListOfPairs
Pair = Array("this", "that")
.Add Pair
.Add Array("herp", "derp")
.Add Array("weet", "tweet")
MsgBox .Item(1)(0) 'Item index is base-1, array index base-0.
Pair = .Item(2)
MsgBox Pair(1)
ReDim Pair(1)
Pair(0) = "another"
Pair(1) = "way"
.Add Pair
MsgBox .Item(4)(1)
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
如果它只是用于存储您可以使用Type:
Public Type Tuple
Item1 As String
Item2 As String
End Type
Run Code Online (Sandbox Code Playgroud)
它比需要一个类进行存储更简洁.
这个问题Types(更广泛地称为UDT)的是,有上,你可以跟他们做什么限制.您可以创建一个UDT数组.您无法创建 UDT 的集合.
就.Net而言,它们最相似Struct.