WHAT YOU WILL LEARN IN THIS CHAPTER
Working with arrays
Working with collections
Covariance and contravariance
In the beginning there were variables, and they were good. The idea that you map a location in memory to a value was a key to tracking a value. However, most of us want to work on data as a set. Taking the concept of a variable holding a value, we moved to the concept of a variable that could reference an array of values. Arrays improved what developers could build but they weren't the end of the line.
Over time certain patterns developed in how arrays were used. Instead of just collecting a set of values, we looked to use arrays to temporarily store values that were awaiting processing, or to provide sorted collections. Each of these patterns started as a best practice for how to build and manipulate array data or to build custom structures that replicate arrays.
The computing world was very familiar with these concepts — for example, using a linked list to enable more flexibility regarding how data is sorted and retrieved. Patterns such as the stack (first in, last out) or queue (first in, first out) were in fact created as part of the original base Class Libraries. Referred to as collections, they provide a more robust and feature-rich way to manage sets of data than arrays can provide. These were common patterns prior to the introduction of .NET, and .NET ...