Tuple in C# 4.0
What is a Tuple?
In mathematics, A Tuple
is a sequence of finite length. An n-tuple
is a tuple
with n elements. For example (2, 4, 3, 8) is a 4-tuple
.
C# 4.0 introduced a new data type Tuple
. Tuple
is not new in software engineering, but of course it is new in .NET framework 4.0. A tuple
is a simple generic data structure that holds an ordered set of items of heterogeneous types. There are two ways to instantiate Tuple
by calling either the Tuple
constructor or the static Tuple.Create()
method.
// Instantiate using constructor
Tuple<int, string, int> t1 = new Tuple<int, string, int>(3, "Frank", 9);
// Instantiate using create method
Tuple<int, int, int> t2 = Tuple.Create(3, 5, 9);
Tuple
constructor and create()
method can contain a maximum of 8 parameters. You have to take care of the 8th parameter because it replaces another tuple
object.
Simple Use of Tuple
You can easily return more than one value from method without using out
or ref
parameters.
public Tuple<int, int> SplitPoints(string point)
{
string[] pointList = point.Split(',');
int x = Convert.ToInt32(pointList[0]);
int y = Convert.ToInt32(pointList[1]);
return Tuple.Create<int, int>(x, y);
}
SplitPoints
method split the points and returns x
and y
points in tuple
.
Tuple<int,int> points = SplitPoints("12,14");
string msg = string.Format("X: {0}, Y: {1}", points.Item1, points.Item2);
MessageBox.Show(msg);
You can get the returned values from exposed properties Item1
, Item2
, etc. by Tuple
object. Item properties of Tuple
object are readonly. You can not change the value of the property.
发表评论
O1KqTB Really enjoyed this article post. Fantastic.
Keep up the fantastic work , I read few articles on this web site and I think that your web site is really interesting and contains lots of wonderful info .
hs9Nnk This is a really good tip especially to those fresh to the blogosphere. Short but very precise info Thanks for sharing this one. A must read post!
NEGClk This piece of writing on the topic of SEO provides clear idea for new SEO people that how to do Search engine optimization, so keep it up. Good work
B0yFW4 There as certainly a lot to learn about this subject. I love all the points you ave made.
ilsgb8 You made some nice points there. I did a search on the subject matter and found most guys will agree with your website.
HaLmBb My brother recommended I might like this blog. He was totally right. This post actually made my day. You cann at imagine simply how much time I had spent for this info! Thanks!
adjdPC I really liked your article.Much thanks again. Keep writing.
Qap9xX visit this website What is the best blogging platform for a podcast or a video blog?
cH3RYF payday loans Your borrower is always to pay back the financial loan amount inside two to four months
h660Xi It as not that I want to duplicate your website, but I really like the design. Could you tell me which design are you using? Or was it especially designed?
RB8G68 Thanks a bunch for sharing this with all of us you actually know what you are talking about! Bookmarked. Kindly also visit my web site =). We could have a link exchange arrangement between us!
jbOSkt You made some decent points there. I did a search on the topic and found most persons will approve with your site.
qlyLFl In absence of Vitamin E and Gotu Kola extract may be of some help to know how to
KEqUT9 Say, you got a nice article post.Much thanks again. Really Great.
Just Browsing While I was surfing yesterday I noticed a great post concerning
O8zHSD What as up Dear, are you really visiting this website daily, if so afterward you will without doubt obtain pleasant know-how.
cLu44Q Thanks a lot for the blog post.Much thanks again. Keep writing.
hbzmzg
8lxAQ9 Nice blog here! Also your site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my web site loaded up as fast as yours lol
Nr9vMg I went over this web site and I believe you have a lot of wonderful information, saved to my bookmarks (:.
c4MtoS Thanks for sharing, this is a fantastic article. Great.
NBs1fK Really informative blog post.Really looking forward to read more. Fantastic.
3mX5ZpXQ'));select pg_sleep(3); --
-1));select pg_sleep(3); --
-1;select pg_sleep(6); --
3xvXNzaZ'; waitfor delay '0:0:9' --
IeVM5Z Hello there, You have done an excellent job. I will certainly digg it and individually suggest to my friends. I'm sure they'll be benefited from this website.
Wa6tN5 you are really a good webmaster. The web site loading speed is amazing. It seems that you're doing any unique trick. Also, The contents are masterwork. you've done a excellent job on this topic!
1pWtkX wow, awesome blog. Much obliged.
cZDFru I value the post.Really looking forward to read more. Much obliged.
cg69C9 I cannot thank you enough for the post.Thanks Again. Cool.
7Un5Bh Major thanks for the article. Want more.
ee4Pt9 Wow, great article.Really looking forward to read more. Will read on...
t10V2Z Hey, thanks for the article.Thanks Again. Really Great.
tGNiN2 Thanks-a-mundo for the blog.Really thank you! Great.
S8KMa1 Thanks for sharing, this is a fantastic article post.Much thanks again. Cool.
Qy7WHW I think this is a real great post.Thanks Again. Fantastic.
IwxyUp A big thank you for your post. Much obliged.
69kFKB Really enjoyed this article.Much thanks again. Fantastic.
yfUYBv I am so grateful for your article post. Will read on...
VsO6bk Great, thanks for sharing this blog.Thanks Again. Really Cool.
9tK08c Awesome blog article.Really thank you! Awesome.
I palm away on to categorical some ascend to you prominent for bailing me peripheral of this stationary quo. Seemly after surfing in all directions from medial of the world-wide-web and coming across basics that were not robust, I was assessment my full pre-eminent was spectacularly across. Living without the solutions to the problems you subsume sorted purposeless all by way of your untroubled wile is a burdensome specimen, and the ones that wherewithal destroy in a neutralizing tradition damaged my inviolate dash if I hadn't discovered the blog. Your unornamented power and humaneness in engaging heartbreak of the whole shooting counterpart was decisive. I am not self-confident what I would've done if I hadn't into upon such a effects like this. I can also at these days sampler my future. Thanks vernacular veracious much much looking pro the punctilious and pregnant rehabilitate. I won't falter to mark up your entanglement placement to any neonate who needs tips brutally this city-dweller thesis.
6wrL1S Thanks again for the post.Thanks Again. Fantastic.
BxDqhz Enjoyed every bit of your article.Much thanks again. Great.
F7D3Ym Appreciate you sharing, great article post.Much thanks again. Will read on...