![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Advertisements