Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

tuples in c#

//You can define tuples with an arbitrary large number of elements:
var t = 
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26);
Console.WriteLine(t.Item26);  // output: 26

//You can explicitly specify the names of tuple fields either in a 
//tuple initialization expression or in the definition of a tuple 
//type, as the following example shows:
var t = (Sum: 4.5, Count: 3);
Console.WriteLine($"Sum of {t.Count} elements is {t.Sum}.");

(double Sum, int Count) d = (4.5, 3);
Console.WriteLine($"Sum of {d.Count} elements is {d.Sum}.");
Source by learn.microsoft.com #
 
PREVIOUS NEXT
Tagged: #tuples
ADD COMMENT
Topic
Name
1+1 =