Class

Pair

Description

Stores key-value pairs.

Name

Type

Shared

Left

Variant

Right

Variant

Methods

Name

Parameters

Returns

Shared

Constructor

left As Variant, right As Variant

Property descriptions

Pair.Left

Left As Variant

The left value of the Pair.

Pair.Right

Right As Variant

The right value of the Pair.

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
```

```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
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
Catch err As TypeMismatchException
' ignore the problem
End Try
Next
```

Compatibility

All project types on all supported operating systems.