1.16. The Hashtable Container
The System.Collections namespace provides a Hashtable container. A Hashtable represents a key/value pair in which the key is used for fast lookup. In other languages, we might call our table map or Dictionary. We'll use the Hashtable object to hold the occurrence count of the individual words.
We'll use the word as the key. The occurrence count is the value. If the word is not yet entered in the table, we add the pair, setting the occurrence count to 1. Otherwise, we use the key to retrieve and increment the occurrence count. Here is what this looks like:
Hashtable words = new Hashtable(); int dim1_length = sentences.GetLength( 0 ); for( int ix = 0; ix < dim1_length; ++ix ) { foreach ( string st in sentences[ ix ...
Get C# Primer: A Practical Approach 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.