Skip to main content

Generic and Anonymous Types

  • Chapter
Introducing Visual C# 2010
  • 1696 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 29.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Authors

Rights and permissions

Reprints 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

Publish with us

Policies and ethics