O'Reilly logo

Beginning Microsoft® Visual C#® 2008 by Eric White, Morgan Skinner, Jon D. Reid, Jacob Hammer Pedersen, Christian Nagel, Karli Watson

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

Chapter 11. Collections, Comparisons, and Conversions

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 so on. 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 objects or values. Arrays, however, have their limitations. The biggest is that once arrays have been created, they have a fixed size, so you can't add new items to the end of an existing array without creating a new one. This often means that the syntax used to ...

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