Chapter 12. Deconstruction and pattern matching

This chapter covers
  • Deconstructing tuples into multiple variables
  • Deconstructing nontuple types
  • Applying pattern matching in C# 7
  • Using the three kinds of patterns introduced in C# 7

In chapter 11, you learned that tuples allow you to compose data simply without having to create new types and allowing one variable to act as a bag of other variables. When you used the tuples—for example, to print out the minimum value from a sequence of integers and then print out the maximum—you extracted the values from the tuple one at a time.

That certainly works, and in many cases it’s all you need. But in plenty of cases, you’ll want to break a composite value into separate variables. ...

Get C# in Depth, Fourth Edition 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.