Click here to Skip to main content
Click here to Skip to main content

Tagged as

Tuple in C# 4.0

, 5 Oct 2009
Rate this:
Please Sign up or sign in to vote.
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:

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)

Share

About the Author

Sohel_Rana
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! PinmemberVizualNeel19-Jan-10 17:20 
GeneralRe: Tuples behaviour! PinmemberSohel_Rana19-Jan-10 18:29 
GeneralRe: Tuples behaviour! PinmemberVizualNeel19-Jan-10 19:23 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 5 Oct 2009
Article Copyright 2009 by Sohel_Rana
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid