In the C# 7.0 language specification added additional capability for working with tuples.

A tuple is essentially a single data structure that consists of a number of parts or elements.

The Tuple>T, …< class was available prior to C# 7.0 and its usage was sometimes clumsy. The individual items in a tuple can be of differing types.

In this post we will explore what Tuples are and why they can be useful when developing applications using C# 7.0

I have previously posted about another exciting and useful C# language enhancements , C# local functions. While creating the code samples for the post I really wanted to include code samples with C# Tuples, but for the sake of brevity and not to over complicate my contrived samples decided to write this separate post.

What are C# Tuples

A tuple is a finite ordered list of elements.
In mathematics, an n-tuple is a sequence (or ordered list) of n elements, where n is a non-negative integer. There is only one 0-tuple, an empty sequence. An n-tuple is defined inductively using the construction of an ordered pair.

Tuples are a popular construct in most functional programming languages such as F#, Haskell, Go, Scala etc. Primarily because it is useful to compose functions directly with other functions that accept tuples. Values are often bundled into one unit conceptually and developers are able pass them all together.

Advantages of tuples

  • Tuples are finite sized in nature i.e. we can not add/delete elements to/from a tuple.
  • Ability to search any element in a tuple.
  • faster than lists, due to they are constant set of values.
  • Tuples can be used as dictionary keys as they contain immutable values


Essential C# 7.0

no-fluff guide to the latest versions of C# for programmers at all levels of experience. Updated to reflect new C# 7.0 features and patterns, it will help you write C# code that’s simple, powerful, robust, secure, and maintainable.

Why tuples in C# ?

There are many instances during development when you need to pass a lists values to functions for processing.

Typically developers will tackle this problem by either creating KeyValuePair<TKey,TValue>, Generic List List Class, Collections or even custom classes. In most cases, those approaches have and will continue to more than satisfactory or even still the most optimum solution.

Some of you reading this may be thinking, tuples aren’t anything really new, after all we’ve had the Tuple Class since .Net Framework 4 .

The Tuple Class was not really a C# concept, rather they are .NET types and in reality fall pretty short from being the true tuples. They were limited due in part that the members had fixed names and never really communicated their purpose. They were also reference types which had significant impact on performance besides the fact that they had no syntactical support within C#.

In C#7, tuples have been added to language to provide a concise way to group values together without having to explicitly define specific types.

Using Tuples

In C#7 tuples have been added to the language, and you can use tuple definitions as types to generics making use of the System.ValueTuple , providing first class syntax support.

Tuples are best for internal and private methods rather than public APIs where a static type is much more helpful to the consumer of your API.

Tuple as a return type

You can stipulate a Tuple as return type for a method

Serialization Concerns

Tuples in C#7 are limited serialization capabilities.

Attempting to serialise our tuple to JSON format

Will result in {"Item1":"Gary","Item2":"Woodfine"} being returned. You’ll notice the Keys have been removed.

How the C# 7 ValueTuple type works

In order to understand this behaviour we need to simplify and decompile our code.

You’ll notice that the de-compiled, the GetFreelancer method is simply syntactic sugar and named elements have been pulled out and added via the TupleElementNames attribute. This is because the ValueTuple type’s named elements are erased at runtime, meaning there’s no runtime representation of them.

No Reflection

The absence of named elements in the compiled source means that it’s not possible to use reflection to get those name elements via reflection, which limits ValueTuple’s utility.

This is because under the bonnet the compiler is erasing the named elements and reverting to the Item1 and Item2 properties, meaning our serialiser doesn’t have access to the properties.


Tuples are a great addition to the C# language and can be extremely useful. However, as with any extension or enhancement to software development languages it is vitally important to understand both the advantages and disadvantages in order to make use of them.

Gary Woodfine

Freelance Full Stack Developer at
Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.

Affiliate Disclaimer

Disclosure: Please note that some of the links included in the blog posts are affiliate links, which means I will earn a commission if you decide to make a purchase.

I only include affiliate links to products, services and companies that I have personal experience and have actually used. I only recommend them because they are helpful and useful, not because of the small commissions I make if you decide to buy something.

Please do not spend any money on these products unless you feel they are relevant, suitable and will help you achieve your goals.

Buying anyone of these products and the commisions earned will not make me an overnite multi millionaire, but they will help to cover the hosting costs and compensate for the countless hours and effort I put in to create meaningful and valuable free content I provide to help others succeed.

You've also undoubtedly noticed that I also use various advertising networks - unless of of course you're using an Ad blocker, this is also an attempt to reduce my monthly deficit I experience in providing free relevant, valuable and on occassion insightful content for the benefit of others.

I only really make some money if people click on the ads, unless of course you consider 1c per 1000 impressions real money!

Bear in mind just how many impressions I need to make before I can cover my £20 hosting costs a month!

If you are using an adblocker and guilt stricken you can of course donate using any of the buttons below, but I won't be holding my breath.

Buy me a coffeeBuy me a coffee