Click here to Skip to main content
Licence CPOL
First Posted 5 Oct 2009
Views 12,930
Bookmarked 2 times

Tuple in C# 4.0

By Sohel_Rana | 5 Oct 2009 | Technical Blog
C# 4.0 includes a new feature called Tuple.

1

2

3
1 vote, 100.0%
4

5
4.00/5 - 1 vote
μ 4.00, σa 5.00 [?]
A Technical Blog article. View original blog here.[^]

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)

About the Author

Sohel_Rana

Web Developer

Bangladesh Bangladesh

Member
Sohel Rana is currently working as Software Engineer in a software firm in Dhaka, Bangladesh. He has years of expertise in working with products like SharePoint, Ektron, DotNetNuke. He's main expertise is in the area of SharePoint.
 
He likes to learn new technologies. He likes to listen music in his spare time.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralTuples behaviour! PinmemberVizualNeel18:20 19 Jan '10  
GeneralRe: Tuples behaviour! PinmemberSohel_Rana19:29 19 Jan '10  
GeneralRe: Tuples behaviour! PinmemberVizualNeel20:23 19 Jan '10  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 5 Oct 2009
Article Copyright 2009 by Sohel_Rana
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid