C# 4.0 Tuple

By [)ia6l0 iii

C# 4.0 provides us a new type of generics - Tuples

Tuples are containers that can be used where immutable data containers are needed. These containers by design can hold up to 8 elements of any type. This overcomes the disadvantage of using an object array to hold data of various types and their performance implication during boxing and unboxing operations.

You can create a tuple using the new or Tuple.Create method:
var newTuple = new Tuple<int, string>(1, "egg");
var newTuple = Tuple.Create<int, string>(2, "bump");

Related FAQs

Named and optional parameters is a new concept introduced in 4.0. The Named Parameters allow you to pass arguments by parameter name instead of parameter position in the signature. Optional Parameters allow parameters to be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted.
C# 4.0 Tuple  (1154 Views)