Tuples types are value types and are used to group multiple data elements in a single data structure.
- Methods are not allowed in tuples.
- Tuple elements are public fields.
namespace MyConsoleApp
{
class Program
{
static void Main(string[] args)
{
(int, double) tuple1 = (10, 100.1);
Console.WriteLine($"This tuple has {tuple1.Item1} and {tuple1.Item2}"); //Output: This tuple has 10 and 100.1
(int Value1, double Value2) tuple2 = (20, 200.2);
Console.WriteLine($"This tuple has {tuple2.Value1} and {tuple2.Value2}"); //Output: This tuple has 20 and 200.2
var tuple3 = (Value1: 30, Value2: 300.3);
Console.WriteLine($"This tuple has {tuple3.Value1} and {tuple3.Value2}"); //Output: This tuple has 30 and 300.3
}
}
}