What are tuples in .Net?

Asked 14-Nov-2017
Viewed 766 times

1 Answer


0

"Tuples "
A tuple is a data structure that provides an easy way to represent any type of data. In .NET & C# programming language Tuples help us to keep your logic clear and very simple.

For Example
Here we define a program that uses the 3 items truple-
using System;
class TrupleProgram
{
    static void Main()
    {
        // Create three-items tuple.
        Tuple<int, string, bool> tuple =   new Tuple<int, string, bool>(100, “Book", true); 

        // Access tuple values or items.
        if (tuple.Item1 == 100)
        {
            Console.WriteLine(tuple.Item1);
        }
        if (tuple.Item2 == "Book")
        {
            Console.WriteLine(tuple.Item2);
        }
        if (tuple.Item3)
        {
            Console.WriteLine(tuple.Item3);
        }
    }
}