- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Nested Tuples in C#
Let us first declare a nested tuple.
var tuple = Tuple.Create(100, 200, 300, 400, 500, 600, Tuple.Create(720, 750, 780),800 );
Above, we added a nested tuple using Tuple.Create.
Now to display elements in a nested tuple, nest the Item properties. Sine 7th item in the tuple is nested, we will be using the following to get the nested items −
tuple.Item7.Item1; tuple.Item7.Item2; tuple.Item7.Item3;
Let us see the complete code.
Example
using System; public class Program { public static void Main() { var tuple = Tuple.Create(100, 200, 300, 400, 500, 600, Tuple.Create(720, 750, 780),800 ); Console.WriteLine(tuple.Item1); Console.WriteLine(tuple.Item2); Console.WriteLine(tuple.Item3); Console.WriteLine(tuple.Item4); Console.WriteLine(tuple.Item5); Console.WriteLine(tuple.Item6); // nested tuple Console.WriteLine("
Nested Tuple..."); Console.WriteLine(tuple.Item7.Item1); Console.WriteLine(tuple.Item7.Item2); Console.WriteLine(tuple.Item7.Item3); Console.WriteLine("
8th element...
"+tuple.Rest.Item1); } }
Output
100 200 300 400 500 600 Nested Tuple... 720 750 780 8th element... 800
- Related Articles
- How to Concatenate tuples to nested tuples in Python
- Addition in Nested Tuples in Python
- Nested Classes in C++
- Nested functions in C
- Nested Classes in C#
- What are Tuples in C#4.0?
- When to use tuples in C#?
- C# Nested Classes
- How to compare two tuples in C#?
- Combining tuples in list of tuples in Python
- Can namespaces be nested in C++?
- What are nested classes in C#?
- What are nested namespaces in C#?
- Count tuples occurrence in list of tuples in Python
- What are nested structures in C language?

Advertisements