Lecture overview -- Keyboard shortcut: 'u'  Previous page: Indexers in C# -- Keyboard shortcut: 'p'  Next page: Example of associating Person with BankAccount -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 14 : 29
Object-oriented Programming in C#
Data Access, Properties, and Methods
Associative Arrays

Associative arrays are generalized arrays that allow indexing via objects of an arbitrary type (not just integers). Indexers provide a natural notation for associative arrays.

An associative array is an array which allows indexing by means of arbitrary objects, not just integers

An associative arrays maps a set of objects (the indexing objects, keys) to another set of objects (the element objects).

/user/normark/oop-csharp-1/sources/c-sharp/indexers-abc/2/a.csThe class A indexed by a string.

An example similar to one of the previous indexer examples. In this example it is illustrated how to index via objects of type string.

/user/normark/oop-csharp-1/sources/c-sharp/indexers-abc/2/b.csA client of A which uses the string indexing of A.

/user/normark/oop-csharp-1/sources/c-sharp/indexers-abc/2/outputOutput from Main in class B.


Associative arrays are in C# implemented by means of hashtables in dictionaries
In the lecture about collections, specifically in the interface IDictionary<K,V> we will see how indexers are can be used to access objects of type V via objects of type K by use of the notation dict[k], where dict is a dictionary and k is a key of type K.