1 // ==++==
2 //
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 //
5 // ==--==
6 /*============================================================
7 **
8 ** Interface:  KeyValuePair
9 **
10 ** <OWNER>Microsoft</OWNER>
11 **
12 **
13 ** Purpose: Generic key-value pair for dictionary enumerators.
14 **
15 **
16 ===========================================================*/
17 namespace System.Collections.Generic {
18 
19     using System;
20     using System.Text;
21 
22     // A KeyValuePair holds a key and a value from a dictionary.
23     // It is used by the IEnumerable<T> implementation for both IDictionary<TKey, TValue>
24     // and IReadOnlyDictionary<TKey, TValue>.
25     [Serializable]
26     public struct KeyValuePair<TKey, TValue> {
27         private TKey key;
28         private TValue value;
29 
KeyValuePairSystem.Collections.Generic.KeyValuePair30         public KeyValuePair(TKey key, TValue value) {
31             this.key = key;
32             this.value = value;
33         }
34 
35         public TKey Key {
36             get { return key; }
37         }
38 
39         public TValue Value {
40             get { return value; }
41         }
42 
ToStringSystem.Collections.Generic.KeyValuePair43         public override string ToString() {
44             StringBuilder s = StringBuilderCache.Acquire();
45             s.Append('[');
46             if( Key != null) {
47                 s.Append(Key.ToString());
48             }
49             s.Append(", ");
50             if( Value != null) {
51                s.Append(Value.ToString());
52             }
53             s.Append(']');
54             return StringBuilderCache.GetStringAndRelease(s);
55         }
56     }
57 }
58