Object Oriented Programming using C#
Generic Collections and how to Serialize them
7 Generic Collections and how to
Serialize them
Introduction
This chapter will start by introducing the reader to generic methods it will then go on to introduce the reader to an
essential part of the .NET framework :- the classes that implement generic collections. Finally it will introduce the idea
of serialization and show how different collections can be serialised as this is a very common task.
Objectives
By the end of this chapter you will be able to....
• Understand the concept of Generic Methods
• Understand the concepts of Collections and the different types of Collection
• Understand the concept of Serialiazation and understand how to serialise the different collections.
This chapter consists of twelve sections :-
- An Introduction to Generic Methods
- An Introduction to Collections
- Different Types of Collections
- Lists
- HashSets
- Dictionaries
- A Simple List Example
- A More Realistic Example Using Lists
- An Example Using Sets
- An example Using Dictionaries
- Serializing and De-serializing Collections
- Summary
7.1 An Introduction to Generic Methods
We have seen previously how methods are identified at run time by their signature i.e. the name of the method and the
list of parameters the method takes.
Thus we can have two methods with the same name. Shown below are two methods that find a highest value... one finds
the highest value given two integer numbers, the other finds the highest value of two double numbers.