Is there a specific reason that we have to refer to the properties in a Tuple as Item1, Item2 etc. This just seems like a bad idea to me as they could easily get mixed up in your code. Wouldn't it be much more meaningful to be able to name your properties ie. Red, Green, Blue?
-
Well the reason you can't is that doing so would require changing the language to allow you to arbitrarily rename the properties of a given type, or give special support to tuples. – Lee Sep 12 '12 at 11:49
-
@spender - No not like writing a class – Paul Matthews Sep 12 '12 at 12:16
-
@Lee - Well yes you would have to change the language to make it work. But it just seems like that's the way it should have been implemented in the first place – Paul Matthews Sep 12 '12 at 12:18
-
@Paul - I don't think so - items in a tuple only have positions, not names. It would have been nice if they'd added support for destructuring tuples however e.g. `var (first, second) = tupleInstance`. As it is, tuples aren't much easier to work with than anonymous classes. – Lee Sep 12 '12 at 12:30
-
1Vote for this feature there: https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/6257234-intellisense-for-tuples – John Apr 06 '16 at 14:06
-
1@Abatonime I voted for that feature thanks – Paul Matthews May 18 '16 at 08:18
-
1We _can_ - [Better naming in Tuple classes than “Item1”, “Item2”](https://stackoverflow.com/q/7745938/465053) – RBT May 30 '18 at 10:10
7 Answers
If you want names, don't use Tuples.
Anonymous type:
var t = new { Green = 1, Red = "nice" };
if (t.Green > 0) ....

- 263,252
- 30
- 330
- 514
The Tuple<...> classes are just normal C# classes. C# does not provide a way to have dynamically-named properties (aside from just using a Dictionary or a dynamic object like ExpandoObject). However, C# does provide something like what you want via anonymous types:
var x = new { Red = 10, Blue = 20, Green = 30 }
var sum = x.Red + x.Blue + x.Green;
The reason anonymous types work is that they are just a convenient syntax for defining a custom tuple class on the fly.
These have the advantage of acting like named tuples, but have the disadvantage of not being nameable by the programmer (so you can't make a method that explicitly returns an anonymous type).

- 20,860
- 17
- 88
- 152
If you want to do this then create a class with the appropriately named properties. A tuple is just a quick and dirty way of avoiding having to write a class or use out params when you want to return multiple values from a method.

- 21,601
- 5
- 62
- 79
-
It's been my experience that tuples in C# are used by lazy programmers. The Item1, Item2, Item3... garbage causes all kinds of code maintenance problems. I quite often mentor new hirers where I work and I strongly discourage the use of tuples in C# code. I always tell them to create a class with appropriately named properties as you've suggested. I've seen code with as many as three distinct type of tuples where I work. It's a nightmare to debug that code. – Mark Jun 05 '16 at 13:29
A tuple is not supposed to contain any meaningful properties. It is just a disposable set of items bunched together in a group.
If you want meaningful property names, make a type with those properties. You can either write a class from scratch and use that class, or use anonymous types.

- 700,868
- 160
- 1,392
- 1,356
-
Pity that C# doesn't offer any syntax sugar to write such a class without boilerplate. – CodesInChaos Sep 12 '12 at 11:48
-
So the moral of the story is to grab the values from the tuple and store them in fields that have a meaningful name. Otherwise you get Item1, Item7, 1tem3 happening throughout your code. Yuck! – Paul Matthews Sep 12 '12 at 12:20
-
Do you always have to work with a tuple from the get-go (i.e. do you use an API that returns a tuple)? – BoltClock Sep 12 '12 at 12:22
-
No, I guess I'm just talking about methods in my own code that return multiple values. It just seems redundant to write a class for maybe one or two methods that do this when there's nothing particularly special about that data. – Paul Matthews Sep 12 '12 at 12:36
You could define the class like this (with generics) if you will always be partial to Red/Blue, otherwise, you can use anonymous types as suggested by others.
class RedBluePair<T1, T2>
{
private T1 _Red;
private T2 _Blue;
public RedBluePair(T1 red, T2 blue)
{
_Red = red;
_Blue = blue;
}
public T1 Red { get { return _Red;} }
public T2 Blue { get { return _Blue;} }
}

- 1,385
- 9
- 11
Reproducing my answer from this post as now it is possible to give names to properties in Tuples.
Starting C# v7.0 now it is possible to name the tuple properties which earlier used to default to names like Item1
, Item2
and so on.
Naming the properties of Tuple Literals:
var myDetails = (MyName: "RBT_Yoga", MyAge: 22, MyFavoriteFood: "Dosa");
Console.WriteLine($"Name - {myDetails.MyName}, Age - {myDetails.MyAge}, Passion - {myDetails.MyFavoriteFood}");
The output on console:
Name - RBT_Yoga, Age - 22, Passion - Dosa
Returning Tuple (having named properties) from a method:
static void Main(string[] args)
{
var empInfo = GetEmpInfo();
Console.WriteLine($"Employee Details: {empInfo.firstName}, {empInfo.lastName}, {empInfo.computerName}, {empInfo.Salary}");
}
static (string firstName, string lastName, string computerName, int Salary) GetEmpInfo()
{
//This is hardcoded just for the demonstration. Ideally this data might be coming from some DB or web service call
return ("Rasik", "Bihari", "Rasik-PC", 1000);
}
The output on console:
Employee Details: Rasik, Bihari, Rasik-PC, 1000
Creating a list of Tuples having named properties
var tupleList = new List<(int Index, string Name)>
{
(1, "cow"),
(5, "chickens"),
(1, "airplane")
};
foreach (var tuple in tupleList)
Console.WriteLine($"{tuple.Index} - {tuple.Name}");
Output on console:
1 - cow 5 - chickens 1 - airplane
I hope I've covered everything. In case, there is anything which I've missed then please give me a feedback in comments.
Note: My code snippets are using string interpolation feature of C# v7 as detailed here.

- 24,161
- 21
- 159
- 240
Yes, You can name tuple properties from C# 7.0.
From this documentation,
You can explicitly specify the names of tuple fields either in a tuple initialization expression or in the definition of a tuple type, as the following example shows:
(int Red, int Green, int Blue) ColorRGB = (0, 0, 255);
// Or
var ColorRGB = (Red: 0, Green: 0, Blue: 255);
Or, If you don't specify a field name, it may be inferred from the name of the corresponding variable in a tuple initialization expression, as the following example shows:
int Red = 0;
int Green = 0;
int Blue = 255;
var ColorRGB = (Red, Green, Blue);

- 156
- 13