0

How do I easily reference to items in nested tuples? My method below feels like more work than it suppose to take.
I think it can be faster and better, but since I recently started programming, I don't know what to call certain programming concepts and how to ask specific targeted questions about it.

My goal was to practise with varaibles and Tuples to set string s to "John␣was␣born␣on␣1-10-2001"

using System;

class Program {
  public static void Main() {
    var name = "John";
    var day = 1;
    var month = 10;
    var year = 2001;
    Tuple<string, Tuple<int, int, int>> person;
    person = Tuple.Create(name, Tuple.Create(day, month, year));
    
    string s = "";
    s = person.Item1 + " was born on " + person.Item2.Item1 + "-" + person.Item2.Item2 + "-" + person.Item2.Item3;
  }
}
BlinxX
  • 13
  • 5
  • wouldn't be better to create a custom, concrete class? Tuples are something that I belive should not have been added to C#, makes code unreadable and ugly. When you read a code that uses tuples you can't infer the intentionality of the code while a well constructed and named class will help you to understand what is its purpose. – Gusman Jun 28 '20 at 14:17
  • Dear Gusman, thank you for your answer. The problem in this example is: This is a school exercise where I have to fill in the 'empty gaps' in the code in order to make the code complete again. Since the code is working and I am studying the way it has been set up I stumbled on the Item2.Item1 etc.. That's why I asked the question if anyone knows how to do this more clean. – BlinxX Jun 28 '20 at 14:19
  • Okokok, if that's an assignment then that's different :). Then, no, it can't be made clearer, that's the problem with tuples and why I say they're ugly and should be avoided. The only thing that I can think is that you can "flatten" it to a single tuple `Tuple` but I'm not sure if that part is something that has been given to you already set. – Gusman Jun 28 '20 at 14:23

0 Answers0