Type Summary

						public struct DictionaryEntry
{
  // Constructors
     public DictionaryEntry (object key, object value);

  // Properties
     public object Key { set; get; }
     public object Value { set; get; }
}

AH Note that we've used properties here when fields would have done. Using properties ensures that we can change the implementation later without breaking user code. In the design of the .NET Framework we preferred using properties over instance fields in almost every case.

JR When using the C# foreach statement with a Hashtable, each element through the loop is a DictionaryEntry. This is not obvious from the documentation and I know many programmers who have gotten stumped by this.

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.