New changes to tuples
A tuple is a finite ordered list of elements. In C#, it's not a new thing, having been available since .NET Framework 4.0. It is useful when you want to return multiple values from a method without creating a separate class or collection to hold the data. Tuples are declared in the manner, Tuple<T1, T2, T3, ...>
and are available under the System
namespace.
By default, a tuple can hold up to eight value types, but you can extend it by adding the reference of System.Runtime
.
Although this is useful when returning multiple values, you need to create an allocation for the System.Tuple<...>
object. The following example demonstrates how to return multiple values using a tuple:
public static Tuple<string, string> GetAuthor() { return new Tuple<string, string>("Kunal Chowdhury", "www.kunal-chowdhury.com"); }
Based on the number of elements, the returned value generates properties dynamically to get...