Class

# Pair

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Stores *key-value* pairs.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                | Type                               | Read-Only | Shared |
|---------------------|------------------------------------|-----------|--------|
| `Left<pair.left>`   | `Variant</api/data_types/variant>` | ✓         |        |
| `Right<pair.right>` | `Variant</api/data_types/variant>` | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                             | Parameters                                                                              | Returns | Shared |
|----------------------------------|-----------------------------------------------------------------------------------------|---------|--------|
| `Constructor<pair.constructor0>` | left As `Variant</api/data_types/variant>`, right As `Variant</api/data_types/variant>` |         |        |

## Property descriptions

<div id="pair.left">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Pair.Left

**Left** As `Variant</api/data_types/variant>`

> The left value of the <span class="title-ref">Pair</span>.
>
> This property is read-only.

<div id="pair.right">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Pair.Right

**Right** As `Variant</api/data_types/variant>`

> The right value of the <span class="title-ref">Pair</span>.
>
> This property is read-only.

## Method descriptions

<div id="pair.constructor0">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Pair.Constructor

**Constructor**(left as `Variant</api/data_types/variant>`, right as `Variant</api/data_types/variant>`)

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Creates a <span class="title-ref">Pair</span> instance that is populated by the passed values.
>
> The following creates the <span class="title-ref">Pair</span> 1:2:
>
> ``` xojo
> Var p As New Pair(1, 2)
> ```
>
> You can also use the `:</api/language/operators/pair_operator>` operator, so the following is equivalent:
>
> ``` xojo
> Var p As Pair = 1 : 2
> ```

## Notes

Use the `:</api/language/operators/pair_operator>` operator to assign the Left and Right values of a single <span class="title-ref">Pair</span> in a `Var</api/language/var>` statement. For example:

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

``` xojo
Var p As New Pair(1, 2)
```

The values of the Left and Right properties cannot be assigned using the `=</api/language/operators/comparison/equals_operator>` operator. For example, the following code will result in a `Cannot Assign a Value to this Property</api/errors>` error:

``` xojo
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 <span class="title-ref">Pair</span> instance and assigns its Left and Right properties to a String:

``` xojo
Var p As Pair = 5 : 6
Var values As String = p.Left.StringValue + ", " + p.Right.StringValue
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

To create a linked list:

``` xojo
Var p As Pair = 1 : 2 : 3 : 4
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The Left property of the first <span class="title-ref">Pair</span> will contain the "1" and the right property will contain a second <span class="title-ref">Pair</span>. The second <span class="title-ref">Pair</span>'s Left property will contain the "2" and its Right property will contain the third <span class="title-ref">Pair</span>, 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</api/language/introspection/introspection>` system:

``` xojo
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</api/user_interface/desktop/desktoplistbox>`:

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

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Object</api/data_types/additional_types/object>` parent class; `Dictionary</api/language/dictionary>` class; `Pair operator</api/language/operators/pair_operator>`.

</div>
