Chapter 11. Collections, Comparisons, and Conversions

WHAT YOU WILL LEARN IN THIS CHAPTER

  • How to define and use collections

  • What different types of collection are available

  • How to compare types and use the is operator

  • How to compare values and overload operators

  • How to define and use conversions

  • How to use the as operator

You've covered all the basic OOP techniques in C# now, but there are some more advanced techniques that are worth becoming familiar with. In this chapter, you look at the following:

  • Collections—Collections enable you to maintain groups of objects. Unlike arrays, which you've used in earlier chapters, collections can include more advanced functionality, such as controlling access to the objects they contain, searching and sorting, and more. You'll learn how to use and create collection classes and learn about some powerful techniques for getting the most out of them.

  • Comparisons—When dealing with objects, you often want to make comparisons between them. This is especially important in collections, because it is how sorting is achieved. You'll look at how to compare objects in a number of ways, including operator overloading, and how to use the IComparable and IComparer interface to sort collections.

  • Conversions—Earlier chapters showed how to cast objects from one type into another. In this chapter, you'll learn how to customize type conversions to suit your needs.

COLLECTIONS

In Chapter 5, you learned how you can use arrays to create variable types that contain a number of ...

Get Beginning Visual C# 2010 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.