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,
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace TuppleApplication
- {
- class Program
- {
- static void Main(string[] args)
- {
- Tuple<string, int, int> tupple = new Tuple<string, int, int>("blue", 1, 2);
- if(tupple.Item1=="blue")
- {
- Console.WriteLine(tupple.Item1);
- }
- if(tupple.Item2==1)
- {
- Console.WriteLine(tupple.Item2);
- }
- if(tupple.Item3==2)
- {
- Console.WriteLine(tupple.Item3);
- }
- Console.ReadLine();
- }
- }
- }
A tuple is a immutable.tupple returns mulyiple values.By using create() method we can create tuple,
var tupple=Tupple.create("red",1);