Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't we give names to properties in Tuples?

Tags:

c#

tuples

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?

like image 387
Paul Matthews Avatar asked Dec 09 '22 21:12

Paul Matthews


1 Answers

If you want names, don't use Tuples.

Anonymous type:

var t = new { Green = 1, Red  = "nice" };

if (t.Green > 0) ....
like image 183
Henk Holterman Avatar answered Dec 11 '22 11:12

Henk Holterman