Tuple Types

Some languages provide a loosely structured way to combine multiple objects (for example, to pass them around in an all-in-one fashion). This comes in handy to overcome the typical single output channel of a method. Output parameters can be used as an alternative to deal with such cases, but they’re more invasive at the method’s call site. When using output parameters, you must introduce local variables and need to specify the out keyword on all such parameters, which can be quite distracting when reading the code:

int res;if (int.TryParse("42", out res))    ...

Tuple types allow multiple objects to be passed around by just wrapping them in an object with multiple (readonly) fields, exposed through properties. For example, with a ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.