c# return tuple code example
Example 1: c# initialize tuple with default values
(double, int) t1 = (4.5, 3);
Console.WriteLine($"Tuple with elements {t1.Item1} and {t1.Item2}.");
(double Sum, int Count) t2 = (4.5, 3);
Console.WriteLine($"Sum of {t2.Count} elements is {t2.Sum}.");
Example 2: c# return two variables of different types
(string, string, int) LookupName(long id)
{
...
return (first, middle, myNum);
}
Example 3: c# tuple
var tupleList = new List<Tuple<int, string, string, string>>();
tupleList.Add(Tuple.Create(1, "Sefat Anam", "Dhaka Bangladesh", "0.1245345"));