What are tuples in C#?

Answer

Tuples are lightweight structures for grouping multiple values without creating a dedicated class. C# 7+ introduced ValueTuple (struct-based, more efficient). Declaration: (string Name, int Age) person = ("Alice", 30); or with inference: var point = (X: 1, Y: 2);. Named elements: point.X, point.Y. Return from method: public (int Min, int Max) GetRange(int[] arr) => (arr.Min(), arr.Max());. Call: var (min, max) = GetRange(data); (deconstruction). Swap variables: (a, b) = (b, a);. The older System.Tuple<T1, T2> class (heap-allocated, access via .Item1, .Item2) is now discouraged. Use tuples for: returning multiple values, temporary groupings, pattern matching, and LINQ groupings. For complex or frequently used value groupings, prefer records or named classes.