About
In this code snippet, we will take a look at tuples in C#.
Tuples allow you to quickly and easily create objects. You can for example use them as a variable or method return data type.
Let’s have a look at the code below to see how to use tuples.
Code:
(string myString, int myInt) myTuple = ("Hello World", 5);
Console.WriteLine(myTuple.myString + " " + myTuple.myInt);
var myOtherTuple = myMethod();
Console.WriteLine(myOtherTuple.Item1 + " " + myOtherTuple.Item2);
Console.ReadLine();
//Tuples can also be used as return types for methods.
static (int, int) myMethod()
{
return (5, 10);
}





