Class
Pair
Description
Stores key-value pairs.
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
Property descriptions
Pair.Left
Left As Variant
The left value of the Pair.
This property is read-only.
Pair.Right
Right As Variant
The right value of the Pair.
This property is read-only.
Method descriptions
Pair.Constructor
Constructor(left as Variant, right as Variant)
Note
Constructors are special methods called when you create an object with the New keyword and pass in the parameters above.
Creates a Pair instance that is populated by the passed values.
The following creates the Pair 1:2:
Var p As New Pair(1, 2)
You can also use the : operator, so the following is equivalent:
Var p As Pair = 1 : 2
Notes
Use the : operator to assign the Left and Right values of a single Pair in a Var statement. For example:
Var p As Pair = 1 : 2
This statement assigns the "1" to the Left property and the "2" to the Right property.
The following is also acceptable:
Var p As New Pair(1, 2)
The values of the Left and Right properties cannot be assigned using the = operator. For example, the following code will result in a Cannot Assign a Value to this Property error:
Var p As Pair = 1 : 2
p.Left = 23 'This will produce a Cannot Assign a Value to This Property error
Sample code
This example creates a Pair instance and assigns its Left and Right properties to a String:
Var p As Pair = 5 : 6
Var values As String = p.Left.StringValue + ", " + p.Right.StringValue
To create a linked list:
Var p As Pair = 1 : 2 : 3 : 4
The Left property of the first Pair will contain the "1" and the right property will contain a second Pair. The second Pair's Left property will contain the "2" and its Right property will contain the third Pair, and so forth. This statement creates four linked pairs.
This example uses an array of Pairs to obtain a class instance's properties and values using the Introspection system:
Var tcp As New TCPSocket
Var ti As Introspection.TypeInfo = Introspection.GetType(tcp)
Var props() As Pair
For Each prop As Introspection.PropertyInfo In ti.GetProperties
props.Add(prop.Name : prop.Value(tcp))
Next prop
The following code displays the Name/Value pairs that were obtained in the previous example in a two-column ListBox:
For Each p As Pair In props
Try
Listbox1.AddRow(p.Left.StringValue)
Listbox1.CellTextAt(Listbox1.LastAddedRowIndex, 1) = p.Right.StringValue
Catch err As TypeMismatchException
' ignore the problem
End Try
Next
Compatibility
All project types on all supported operating systems.
See also
Object parent class; Dictionary class; : operator.