The Microsoft .NET engineering team has posted a blog discussing its plans to add support for tuples to C# and Visual Basic. In a blog posting on the subject, Anthony D. Green, program manager on the managed languages team at Microsoft, wrote about the exact method of tuple implementation.
“A tuple is vaguely like an array in that it’s a data structure that bundles up multiple values together as a unit, except whereas in an array, each element of the array has the same type, in a tuple every element may have a different type,” he wrote.
(Related: Microsoft wants to bring more opportunities to .NET developers)
Tuples can make it easier for developers to return multiple values from a function, and can alleviate the need to make specialty types for catching remainders and quotients from a single method. Tuples will also have names.
“This means you get all the self-documenting names of declaring your own structure but with a lightweight syntax,” wrote Green. “This is similar to the anonymous types VB has already but with the benefit that you can pass them around outside of methods. This makes VB tuples halfway between what languages like F# call a tuple and what they call a record. We think this is the sweet spot.
“We think tuples will be very helpful with reducing a lot of the ceremony and internal bookkeeping around returning and passing data within your project by making bundling data as easy as possible. And when you’re using the powerful Async feature this really shines, because in Async functions, you can’t even have ByRef parameters at all, so you can’t use the old strategy.”
Full design documentation for tuples is available on Microsoft’s GitHub page.