C# Tuple

Tuple.
The Tuple is a typed, immutable, generic construct. It has many items, each item can have any type(even complex items like array inside it). The Tuple type is a class. Once we create the Tuple, we cannot change the values of its fields.
Tuple is generally used as a short-term container.

using System;
class Program
{
    static void Main()
    {
        Tuple<int, string, bool> tuple =new Tuple<int, string, bool>(1, "cat", true);
        Console.WriteLine(tuple.Item1);
        Console.WriteLine(tuple.Item2);
        Console.WriteLine(tuple.Item3);
    }
}

Output
1
cat
True

The Tuple.Create method returns a reference to a tuple. eg: var tuple = Tuple.Create(“cat”, 2, true);

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.