Introduction To Tuple

What is Tuple?

Tuple is a type of class which once created, cannot change the type of fields. Tuple is a fixed type ordered sequence. A tuple is an ordered list of elements. In mathematics, an n-tuple is an ordered list of n elements, where n is a non-negative integer, like tuple has stored seven elements and more than seven elements are also possible.


Names,
  • A 2 tuple is called a pair.
  • A 3 tuple is called a tripple.
  • A 4-tuple is called a quadruple.
  • A 5-tuple is called a quintuple.
  • A 6-tuple is called a sextuple.
  • A 7-tuple is called a septuple.

Larger tuples are called n-tuples

Tripple Example:Three items stored in one tuple is called tripple; in this I wrote one example for this tripple,

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. namespace TuppleApplication  
  8. {  
  9.     class Program  
  10.     {  
  11.         static void Main(string[] args)  
  12.         {  
  13.             Tuple<string, intint> tupple = new Tuple<string, intint>("blue", 1, 2);  
  14.             if(tupple.Item1=="blue")  
  15.             {  
  16.                 Console.WriteLine(tupple.Item1);  
  17.             }  
  18.             if(tupple.Item2==1)  
  19.             {  
  20.                 Console.WriteLine(tupple.Item2);  
  21.             }  
  22.             if(tupple.Item3==2)  
  23.             {  
  24.                 Console.WriteLine(tupple.Item3);  
  25.             }  
  26.             Console.ReadLine();  
  27.         }  
  28.     }  
  29. }  
A tuple is a immutable.tupple returns mulyiple values.By using create() method we can create tuple,

var tupple=Tupple.create("red",1);

 

Next Recommended Reading C# 7.0 New Feature - Tuples In C# 7