Click here to Skip to main content
15,887,302 members
Articles / Programming Languages / C# 4.0

Tuple in C# 4.0

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
5 Oct 2009CPOL 33.8K   4   3
C# 4.0 includes a new feature called Tuple.

C# 4.0 includes a new feature called Tuple. In mathematics, tuple is an ordered list of specific number of values called the components of the tuple. For example, a 3-tuple name may be used as: (First-Name, Middle-Name, Last-Name).

Let's take a look at the following example:

C#
public Tuple<int, int> GetDivAndRemainder(int i, int j) 
{ 
    Tuple.Create(i/j, i%j); 
} 
public void CallMethod() 
{ 
    var tuple = GetDivAndRemainder(10,3); 
    Console.WriteLine("{0} and {1}", tuple.item1, tuple.item2); 
} 

In the above example, the method can return a tuple which has two integer values. So using tuple, we can return multiple values. So this will help lazy programmers to write less code but do more. One great use of tuple might be returning multiple values from a method.

To get more information on Tuple, visit the following links:

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect ImpleVista Aps
Denmark Denmark
Sohel has more than six years of experience in professional software development with extensive involvement in Web based Object-Oriented, Multi-Tiered application design and development. He's Familiar with Test Driven Development (TDD) and refactoring techniques as well as having expertise in architecturing large enterprise applications. He has Experience in working with Content Management System and Portal Management System tools like SharePoint, DotNetNuke, Ektron.

Over last few years, he’s involved in development with projects on Microsoft SharePoint and received Microsoft MVP for SharePoint Server Development in the year 2011 and 2012. Currently he's working in a software company located Copenhagen,Denmark on a project integrating SharePoint and SAP. You can read his popular blog at: http://ranaictiu-technicalblog.blogspot.com

Comments and Discussions

 
GeneralTuples behaviour! Pin
VizualNeel19-Jan-10 17:20
professionalVizualNeel19-Jan-10 17:20 
GeneralRe: Tuples behaviour! Pin
Sohel_Rana19-Jan-10 18:29
Sohel_Rana19-Jan-10 18:29 
GeneralRe: Tuples behaviour! Pin
VizualNeel19-Jan-10 19:23
professionalVizualNeel19-Jan-10 19:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.