What are tuples in .Net?

0 votes
153 views
Sunita  Singh asked 14-Nov-2017 in programming by Sunita Singh

What are tuples in .Net?

1 Answer

0 votes
Arti Mishra answered 31-Jul-2018 by Arti Mishra
"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);
        }
    }
}