C# | How to get Fourth Element of the Tuple?

Tuple is a data structure which gives you the easiest way to represent a data set which has multiple values that may/may not be related to each other. Item4 Property is used to get the fourth element of the given tuple. It is not applicable on 1-Tuple, 2-Tuple, and 3-Tuple but applicable on all other remaining tuples.

Syntax:

public T4 Item4 { get; }

Here, T4 is the value of the current Tuple<> object’s fourth component. This Tuple<> can be 4-tuple, or 5-tuple, or 6-tuple, or 7-tuple, or 8-tuple.



Example: In the below code, you can see that we are accessing the fourth element of each tuple.

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate how to get 
// the fourth element of the tuple
using System;
  
class GFG {
  
    // Main method
    static public void Main()
    {
  
  
        // Taking 4-tuple
        var st4 = Tuple.Create("Rohan", 29, "EC", 2015);
        Console.WriteLine("Student-4 Year: " + st4.Item4);
  
        // Taking 5-tuple
        var st5 = Tuple.Create("Siya", 22, "EEE", 2017,
                                           "20-Mar-1993");
  
        Console.WriteLine("Student-5 Year: " + st5.Item4);
  
        // Taking 6-tuple
        var st6 = Tuple.Create("Riya", 24, "ME", 2015,
                               "30-May-2015", 230134832);
  
        Console.WriteLine("Student-6 Year: " + st6.Item4);
  
        // Taking 7-tuple
        var st7 = Tuple.Create("Rohit", 21, "IT", 2017, 
                        "21-Apr-1998", 384749829, 20000);
  
        Console.WriteLine("Student-7 Year: " + st7.Item4);
  
        // Taking 8-tuple
        var st8 = Tuple.Create("Manita", 24, "CSE", 2016, 
                   "03-Aug-1991", 235678909, 34000, "C#");
  
        Console.WriteLine("Student-8 Year: " + st8.Item4);
    }
}

chevron_right


Output:

Student-4 Year: 2015
Student-5 Year: 2017
Student-6 Year: 2015
Student-7 Year: 2017
Student-8 Year: 2016


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.