The Labs \ Source Viewer \ SSCLI \ System.Collections.Generic \ KeyValuePair

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*============================================================
  16. **
  17. ** Interface:  KeyValuePair
  18. **
  19. **
  20. ** Purpose: Generic key-value pair for dictionary enumerators.
  21. **
  22. **
  23. ===========================================================*/
  24. namespace System.Collections.Generic
  25. {
  26.    
  27.     using System;
  28.     using System.Text;
  29.    
  30.     // A KeyValuePair holds a key and a value from a dictionary.
  31.     // It is returned by IDictionaryEnumerator::GetEntry().
  32.     [Serializable()]
  33.    
  34.     public struct KeyValuePair<TKey, TValue>
  35.     {
  36.         private TKey key;
  37.         private TValue value;
  38.        
  39.         public KeyValuePair(TKey key, TValue value)
  40.         {
  41.             this.key = key;
  42.             this.value = value;
  43.         }
  44.        
  45.         public TKey Key {
  46.             get { return key; }
  47.         }
  48.        
  49.         public TValue Value {
  50.             get { return value; }
  51.         }
  52.        
  53.         public override string ToString()
  54.         {
  55.             StringBuilder s = new StringBuilder();
  56.             s.Append('[');
  57.             if (Key != null) {
  58.                 s.Append(Key.ToString());
  59.             }
  60.             s.Append(", ");
  61.             if (Value != null) {
  62.                 s.Append(Value.ToString());
  63.             }
  64.             s.Append(']');
  65.             return s.ToString();
  66.         }
  67.     }
  68. }

Developer Fusion