Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public fields | Public static fields | Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Pair< T1, T2 > Struct Template Reference

A tuple of two values, A and B, in a struct. More...


Source file:
Inheritance diagram for Loyc.Pair< T1, T2 >:
Loyc.IHasValue< out T >

Remarks

A tuple of two values, A and B, in a struct.

The BCL has a KeyValuePair{A,B} structure that has two problems: not all pairs are key-value pairs, and its name is overly long and clumsy. There is also a Tuple{T1,T2} type, whose problem is that it requires a heap allocation.

For compatibility with KeyValuePair{A,B}, this structure has Key and Value properties. For compatibility with Tuple{A,B}, it has Item1 and Item2 properties. Respectively, these properties refer to the A and B fields.

This is a mutable structure. Some people fear mutable structures, but I have heard all the arguments, and find them unpersuasive. The most common pitfall, changing a copy and expecting a different copy to change, is nothing more than ignorance about how structs work. The second most common pitfall involves mutator methods inside a struct, but this struct doesn't have any of those (and the problem would largely be fixed by a compiler-recognized attribute like [Mutates] that would detect potential problems).

Public fields

T1 A
 
T2 B
 

Public static fields

static readonly
EqualityComparer< T1 > 
T1Comparer = EqualityComparer<T1>.Default
 
static readonly
EqualityComparer< T2 > 
T2Comparer = EqualityComparer<T2>.Default
 

Properties

T1 Item1 [get, set]
 
T2 Item2 [get, set]
 
T1 Key [get, set]
 
T2 Value [get, set]
 
- Properties inherited from Loyc.IHasValue< out T >
Value [get]
 

Public Member Functions

 Pair (T1 a, T2 b)
 
bool Equals (Pair< T1, T2 > rhs)
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
override string ToString ()
 
int CompareTo (Pair< T1, T2 > other)
 
int CompareTo (object obj)
 

Static Public Member Functions

static implicit operator KeyValuePair< T1, T2 > (Pair< T1, T2 > p)
 
static bool operator== (Pair< T1, T2 > a, Pair< T1, T2 > b)
 
static bool operator!= (Pair< T1, T2 > a, Pair< T1, T2 > b)