A Blatant Programming Question
-
Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)
Will Rogers never met me.
-
Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)
Will Rogers never met me.
-
Yup, that's the beast. What's it good for?:confused:
Will Rogers never met me.
-
Yup, that's the beast. What's it good for?:confused:
Will Rogers never met me.
People that are too lazy to write classes? Or have a class that would contain many properties? Seem to be the general idea: C# 4 - Tuples[^]
-
Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)
Will Rogers never met me.
I nearly mistook the Tuple for a Tupe, and as I read about it I think both are prone to the same question. What's it good for :laugh:
-
People that are too lazy to write classes? Or have a class that would contain many properties? Seem to be the general idea: C# 4 - Tuples[^]
Kenneth Haugland wrote:
People that are too lazy to write classes?
oh the arrogance of the young ... I'd suggest Tuples were around before c++, c#, and 'class' related constructs 'g'
-
Kenneth Haugland wrote:
People that are too lazy to write classes?
oh the arrogance of the young ... I'd suggest Tuples were around before c++, c#, and 'class' related constructs 'g'
Not that young Im afraid. :-D So Tuples are a lightweight class in many ways?
-
I nearly mistook the Tuple for a Tupe, and as I read about it I think both are prone to the same question. What's it good for :laugh:
A tupee is good for demonstrating one's vanity, at least. I can think of no use for a tuple, though; hence the question...
Will Rogers never met me.
-
People that are too lazy to write classes? Or have a class that would contain many properties? Seem to be the general idea: C# 4 - Tuples[^]
Good article, but I still have no idea why I'd want to use a tuple. It seems like something added to C# just to make people familiar with other languages which use such constructs more comfortable. Interesting, but not something I'll spend my retirement years mastering... :)
Will Rogers never met me.
-
Not that young Im afraid. :-D So Tuples are a lightweight class in many ways?
So far I've only found two Methods - .Create and .Item_x_ - so I'd call that fairly lightweight. :-D
Will Rogers never met me.
-
So far I've only found two Methods - .Create and .Item_x_ - so I'd call that fairly lightweight. :-D
Will Rogers never met me.
:laugh: Only the items could be anything, seems very much to resemble a list of different objects, witch you could send around without createing a class. I cant think of a use. WPF and binding seem to make them unnessecary, but what do I know... Im sure that someone will tell you that the planets existens depended on this class...
-
Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)
Will Rogers never met me.
Things I find them very useful for: - Returning multiple values without the bother of out or ref parameters, and so I don't have to make a whole other class. - Working with Enumerable.Zip - Keys into Dictionarys so I don't have to bother writing a fast and correct Equals and GetHashCode() methods - Ensuring immutability. Unlike an array, the items are readonly. An array is faster and nicer, but it's mutable, which is sometimes a pain.
-
Good article, but I still have no idea why I'd want to use a tuple. It seems like something added to C# just to make people familiar with other languages which use such constructs more comfortable. Interesting, but not something I'll spend my retirement years mastering... :)
Will Rogers never met me.
The big thing is that they save you from creating a throwaway class just to manage a small set of items. Apparently this is something the functional languages like F# do often. I'll freely admit though after I read the article I had a strong whiff of
#define
.Software Zen:
delete this;
-
A tupee is good for demonstrating one's vanity, at least. I can think of no use for a tuple, though; hence the question...
Will Rogers never met me.
Exactly. My approach: if you haven't got it, flaunt it (see profile picture for details).
Software Zen:
delete this;
-
Things I find them very useful for: - Returning multiple values without the bother of out or ref parameters, and so I don't have to make a whole other class. - Working with Enumerable.Zip - Keys into Dictionarys so I don't have to bother writing a fast and correct Equals and GetHashCode() methods - Ensuring immutability. Unlike an array, the items are readonly. An array is faster and nicer, but it's mutable, which is sometimes a pain.
Anonymous classes handle most of these cases and cleaner in my opinion. Who knows what Item0 and Item1 and Item2 is?
-
:laugh: Only the items could be anything, seems very much to resemble a list of different objects, witch you could send around without createing a class. I cant think of a use. WPF and binding seem to make them unnessecary, but what do I know... Im sure that someone will tell you that the planets existens depended on this class...
Would this resemble a Bag in any way? In some versions of C++ I've seen a Bag collection that was used as the name implies to hold any data type.
VS2010/Atmel Studio 6.0 ToDo Manager Extension
Version 3.0 now available. There is no place like 127.0.0.1 -
Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)
Will Rogers never met me.
Tuple types were added to facilitate language interoperability and to reduce duplication in the framework. As you noticed a tuple is a simple generic data structure that holds an ordered set of items. Tuples are supported natively in languages such as F# and IronPython.
Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS Whenever methodologies become productized, objectivity is removed from the equation. -- Mike Myatt
-
Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)
Will Rogers never met me.
Well, my biased opinion: Tuples were added to .NET languages because they are an important feature of functional languages, and since Microsoft was adding F# to be IL compatible, they needed support for tuples. Tuples are a simple way of creating typed structures on the fly (type is inferred by the usage of their items), without having to actually create a class or struct. In F#, they are even simpler than records. So, given that, tuples are useful when you need to return more than one value from a function call. For example, a success/fail along with a success/default value. Or the real and imaginary components of a complex number. I don't find tuples necessarily that useful for passing data into a function, the exception being passing the tuple return of one function into another function. Tuples do not replace lists, arrays, or other collections. Does that help? Marc
-
People that are too lazy to write classes? Or have a class that would contain many properties? Seem to be the general idea: C# 4 - Tuples[^]
Laziness - that's why I occasionally use them. I feel dirty afterwards.
-
Not really... ;P There's a discussion going on in the C# forum about Tuples, and I'm curious what one would use them for. From browsing VS2010 Help, it appears to me that this is a way to make vectors of mixed types which, if used as a type for an Array, could allow mixed arrays. Is this correct? And what would be an example of using such a beast? Wouldn't a dataset be more efficient? Enquiring minds want to know, as they say at the checkout counter. :)
Will Rogers never met me.
If you can't think of a reason, and a custom class or struct will suffice (and be more descriptive), then write a class or struct. I'll occasionally use a Tuple briefly to test something before I write a class. If you can use a class, you should use a class.