summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs')
-rw-r--r--src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs b/src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs
new file mode 100644
index 0000000000..d232e20d8b
--- /dev/null
+++ b/src/mscorlib/src/System/Collections/Generic/KeyValuePair.cs
@@ -0,0 +1,55 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+/*============================================================
+**
+** Interface: KeyValuePair
+**
+**
+**
+**
+** Purpose: Generic key-value pair for dictionary enumerators.
+**
+**
+===========================================================*/
+namespace System.Collections.Generic {
+
+ using System;
+ using System.Text;
+
+ // A KeyValuePair holds a key and a value from a dictionary.
+ // It is used by the IEnumerable<T> implementation for both IDictionary<TKey, TValue>
+ // and IReadOnlyDictionary<TKey, TValue>.
+ [Serializable]
+ public struct KeyValuePair<TKey, TValue> {
+ private TKey key;
+ private TValue value;
+
+ public KeyValuePair(TKey key, TValue value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public TKey Key {
+ get { return key; }
+ }
+
+ public TValue Value {
+ get { return value; }
+ }
+
+ public override string ToString() {
+ StringBuilder s = StringBuilderCache.Acquire();
+ s.Append('[');
+ if( Key != null) {
+ s.Append(Key.ToString());
+ }
+ s.Append(", ");
+ if( Value != null) {
+ s.Append(Value.ToString());
+ }
+ s.Append(']');
+ return StringBuilderCache.GetStringAndRelease(s);
+ }
+ }
+}