How to get third Element of the ValueTuple in C#?
ValueTuple is a structure introduced in C# 7.0 which represents the value type Tuple. It allows you to store a data set which contains multiple values that may or may not be related to each other. Item3 Property is used to get the third unnamed element of the given value tuple. It is applicable on every value tuple like 3-ValueTuple, 4-ValueTuple, and so on.
Syntax:
public T3 Item3;
Here, T3 is the field value of a ValueTuple<> structure. This ValueTuple<> can be 3-ValueTuple, or 4-ValueTuple, or 5-ValueTuple, or 6-ValueTuple, or 7-ValueTuple, or 8-ValueTuple.
Example: In the below code, you can see that we are accessing the third element of each value tuple.
// C# program to illustrate how to get // the third element of value tuple using System; class GFG { // Main Method static public void Main() { Console.WriteLine("C# Topics:"); // Creating a value tuple // with three elements var ValTpl3 = ValueTuple.Create("ArrayList", "List", "Queue"); // Accessing the third element of // 3-ValueTuple using Item property Console.WriteLine(ValTpl3.Item3); // Creating a value tuple // with four elements var ValTpl4 = ValueTuple.Create("Stack", "Dictionary", "LinkedList", "Interface"); // Accessing the third element of // 4-ValueTuple using Item property Console.WriteLine(ValTpl4.Item3); // Creating a value tuple with five elements var ValTpl5 = ValueTuple.Create("Identifiers", "Data Types", "Keywords", "Access Modifiers", "Operators"); // Accessing the third element of // 5-ValueTuple using Item property Console.WriteLine(ValTpl5.Item3); // Creating a value tuple with six elements var ValTpl6 = ValueTuple.Create("Nullable Types", "Class", "Structure", "Indexers", "Switch Statement", "Loops"); // Accessing the third element of // 6-ValueTuple using Item property Console.WriteLine(ValTpl6.Item3); // Creating a value tuple with seven elements var ValTpl7 = ValueTuple.Create("Inheritance ", "Constructors", "Encapsulation", "Abstraction", "Static Class", "Partial Classes", "this keyword"); // Accessing the third element of // 7-ValueTuple using Item property Console.WriteLine(ValTpl7.Item3); // Creating a value tuple with eight elements var ValTpl8 = ValueTuple.Create("Methods", "Method Hiding", "Optional Parameters", "Anonymous Method", "Partial Methods", "Local Function", "Delegates", "Destructors"); // Accessing the third element of // 8-ValueTuple using Item property Console.WriteLine(ValTpl8.Item3); } } |
C# Topics: Queue LinkedList Keywords Structure Encapsulation Optional Parameters
Recommended Posts:
- How to get First Element of the ValueTuple in C#?
- How to get fifth Element of the ValueTuple in C#?
- How to get Second Element of the ValueTuple in C#?
- How to get seventh Element of the ValueTuple in C#?
- How to get sixth Element of the ValueTuple in C#?
- How to get fourth Element of the ValueTuple in C#?
- ValueTuple in C#
- How to create 6-ValueTuple in C#?
- C# | ValueTuple <T1,T2,T3> Struct
- How to create 7-ValueTuple in C#?
- C# | ValueTuple <T1,T2,T3,T4,T5> Struct
- C# | ValueTuple <T1,T2,T3,T4> Struct
- How to create 5-ValueTuple in C#?
- ValueTuple Struct in C#
- How to create 8-ValueTuple in C#?
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.



