Abstract
In this chapter, we examined generic and anonymous types. Generic types let us constrain the types that a class will work with but do so in a flexible way. Generics can take a while to get used to, but they can be invaluable, especially when it comes to collection classes, which are discussed in Part III of this book. We also looked at the advanced topic of generic covariance and contravariance. Don’t worry if these topics make no sense. This is a feature that causes even the best programmers to scratch their heads. If that section made little sense, then my advice is to ignore it for the moment, returning to only when the need arises. Most programs do not require covariant or contravariant generic classes to function.
At the end of this chapter, we took a brief look at anonymous types. Our examination was brief because they have such limited functionality. But don’t dismiss them. We will see them again in the LINQ chapter, where their power and flexibility will become apparent.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2010 Adam Freeman
About this chapter
Cite this chapter
Freeman, A. (2010). Generic and Anonymous Types. In: Introducing Visual C# 2010. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4302-3172-1_15
Download citation
DOI: https://doi.org/10.1007/978-1-4302-3172-1_15
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4302-3171-4
Online ISBN: 978-1-4302-3172-1
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)