Data Structures and Collections


In this chapter we introduce a number of .NET data structures and containers that allow us to store and manage collections of objects. In particular, we are interested in those data structures that are of relevance to financial applications, for example:

  • Predefined array classes.
  • Modelling dates and time.
  • Sequential data structures such as lists and arrays.
  • Random access data structures such as sets and dictionaries.

The .NET framework provides two separate collection libraries. The first library models collections whose elements are of type object, which is the type that all other types derive from. This feature allows the developer to store and manage data of any specific type. The downside is that we must cast the data in the collections to the specific type that we expect. The second library is generic and it allows the developer to store and extract data without having to cast the data. This is the approach that we take in this chapter (and in this book in general). The resulting code is easier to maintain and is more robust than the code based on the first library. In general, we find that the generic programming model is the most appropriate paradigm in this context. In Chapter 6 we will use .NET collections to create data structures that model the kinds of data that we need in finance applications.

The main goal of Chapters 5 and 6 is to introduce .NET and user-defined data structures that we shall use ...

Get C# for Financial Markets now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.