0Pricing
C# Academy · Lesson

Value Tuples Basics

Create lightweight tuples for grouped data.

What Is a Tuple?

A tuple groups several values into one lightweight bundle without defining a class. C# value tuples use parentheses: (int, string).

using System;

class Program
{
    static void Main()
    {
        (int, string) pair = (1, "one");
        Console.WriteLine(pair.Item1 + " = " + pair.Item2);
    }
}

Creating a Value Tuple

Write the values in parentheses. The compiler infers the tuple type from them.

using System;

class Program
{
    static void Main()
    {
        var point = (3, 4);
        Console.WriteLine("x=" + point.Item1 + ", y=" + point.Item2);
    }
}

All lessons in this course

  1. Value Tuples Basics
  2. Named Tuple Elements
  3. Deconstruction
  4. Tuples as Method Return Values
← Back to C# Academy