Another new feature in the .NET 4 Framework is support for tuple,which are similar to anonymous classes that you can create on the fly. A tuple is a data structure used in many functional and dynamic languages, such as F# and Iron Python. By providing common tuple types in the BCL, we are helping to better facilitate language interoperability. Many programmers find tuple to be convenient, particularly for returning multiple values from methods.
Here is a code which uses a function that returns two values.
class Program
{
static void Main(string[] args)
{
//Getting the values from the Tuple Function
Tuple<string, string> details = GetDetails();
Console.WriteLine("FirstName : {0}, LastName :{1}", details.Item1, details.Item2);
Console.Read();
}
//Tuple function, which reads two values from
//user and returns to the main
static Tuple<string, string> GetDetails()
{
Console.Write("Enter First Name:");
string _firstName = Console.ReadLine();
Console.Write("Enter Last Name:");
string _lastName = Console.ReadLine();
return new Tuple<string, string>(_firstName, _lastName);
}
}
You can find more details about Tuples in MSDN : Tuple Class