6

In C# .Net 4.0 tuples has been introduced.

What would be the best example of how tuples can be used in a meaningful way?

BanditoBunny
  • 3,658
  • 5
  • 32
  • 40
  • 1
    Sadly the true "power" of Tuples only really shines with *full* language support -- a clean syntax and higher-order operations like decomposition. Using Tuples in a language like F# or Scala is a good bit different than using them in C#. Anonymous types can function like Records ("tuples with named slots") but have the drawback that they can't be exposed across methods; `Tuple` can be exposed as it's just "a normal type". –  Aug 25 '11 at 21:59
  • A good use case for tuples: http://stackoverflow.com/questions/7967523/multi-variable-switch-statement-in-c-sharp/7967631#7967631 – BanditoBunny Nov 02 '11 at 09:25

1 Answers1

11

Here are a few resources that mention the purposes of Tuples, how they can be used and what they can be used for:

The Practical Usage of Tuples in C#

Making Use of Tuples

Using Tuples in .NET 4.0 | Stack Overflow

Tuple Support in C# | Stack Overflow

Usages and Advantages of Tuples | DotNetSpeaks

Summary:

Basically, the Tuple functions as a convenient way to NOT make a custom class to accomplish something. It is highly flexible and could provide a variety of uses, however since it can be very generic, you should be sure to properly document its usage.

Juggerbot
  • 103
  • 4
Rion Williams
  • 74,820
  • 37
  • 200
  • 327