Chapter 11. Composition using tuples

 

This chapter covers

  • Using tuples to compose data
  • Tuple syntax: literals and types
  • Converting tuples
  • How tuples are represented in the CLR
  • Alternatives to tuples and guidelines for their use

Back in C# 3, LINQ revolutionized how we write code to handle collections of data. One of the ways it did that was to allow us to express many operations in terms of how we want to handle each individual item: how to transform an item from one representation to another, or how to filter items out of the result, or how to sort the collection based on a particular aspect of each item. For all that, LINQ didn’t give us many new tools for working with noncollections.

Anonymous types provide one kind of composition but with the huge restriction of being useful only within a block of code. You can’t declare that a method returns an anonymous type precisely because the return type can’t be named.

11.1. Introduction to tuples

 

11.2. Tuple literals and tuple types

 
 

11.3. Tuple types and conversions

 
 

11.4. Tuples in the CLR

 
 
 

11.5. Alternatives to tuples

 
 
 
 

11.6. Uses and recommendations

 
 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest