O'Reilly logo

C# for Financial Markets by Andrea Germani, Daniel J. Duffy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5

Data Structures and Collections

5.1 INTRODUCTION AND OBJECTIVES

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required