Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. A Blatant Programming Question

A Blatant Programming Question

Scheduled Pinned Locked Moved The Lounge
questioncsharpdata-structureshelptutorial
60 Posts 28 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Kenneth Haugland

    We are talking about this[^]?

    R Offline
    R Offline
    Roger Wright
    wrote on last edited by
    #3

    Yup, that's the beast. What's it good for?:confused:

    Will Rogers never met me.

    K 1 Reply Last reply
    0
    • R Roger Wright

      Yup, that's the beast. What's it good for?:confused:

      Will Rogers never met me.

      K Offline
      K Offline
      Kenneth Haugland
      wrote on last edited by
      #4

      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[^]

      G R R 3 Replies Last reply
      0
      • R Roger Wright

        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.

        K Offline
        K Offline
        Kenneth Haugland
        wrote on last edited by
        #5

        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:

        R 1 Reply Last reply
        0
        • K Kenneth Haugland

          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[^]

          G Offline
          G Offline
          Garth J Lancaster
          wrote on last edited by
          #6

          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'

          K G 2 Replies Last reply
          0
          • G Garth J Lancaster

            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'

            K Offline
            K Offline
            Kenneth Haugland
            wrote on last edited by
            #7

            Not that young Im afraid. :-D So Tuples are a lightweight class in many ways?

            R 1 Reply Last reply
            0
            • K Kenneth Haugland

              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:

              R Offline
              R Offline
              Roger Wright
              wrote on last edited by
              #8

              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.

              G 1 Reply Last reply
              0
              • K Kenneth Haugland

                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[^]

                R Offline
                R Offline
                Roger Wright
                wrote on last edited by
                #9

                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.

                G 1 Reply Last reply
                0
                • K Kenneth Haugland

                  Not that young Im afraid. :-D So Tuples are a lightweight class in many ways?

                  R Offline
                  R Offline
                  Roger Wright
                  wrote on last edited by
                  #10

                  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.

                  K 1 Reply Last reply
                  0
                  • R Roger Wright

                    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.

                    K Offline
                    K Offline
                    Kenneth Haugland
                    wrote on last edited by
                    #11

                    :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...

                    Mike HankeyM J M 3 Replies Last reply
                    0
                    • R Roger Wright

                      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.

                      P Offline
                      P Offline
                      Phil Martin
                      wrote on last edited by
                      #12

                      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.

                      L A 2 Replies Last reply
                      0
                      • R Roger Wright

                        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.

                        G Offline
                        G Offline
                        Gary R Wheeler
                        wrote on last edited by
                        #13

                        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;

                        M 1 Reply Last reply
                        0
                        • R Roger Wright

                          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.

                          G Offline
                          G Offline
                          Gary R Wheeler
                          wrote on last edited by
                          #14

                          Exactly. My approach: if you haven't got it, flaunt it (see profile picture for details).

                          Software Zen: delete this;

                          1 Reply Last reply
                          0
                          • P Phil Martin

                            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.

                            L Offline
                            L Offline
                            leppie
                            wrote on last edited by
                            #15

                            Anonymous classes handle most of these cases and cleaner in my opinion. Who knows what Item0 and Item1 and Item2 is?

                            IronScheme
                            ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                            J P B 3 Replies Last reply
                            0
                            • K Kenneth Haugland

                              :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...

                              Mike HankeyM Offline
                              Mike HankeyM Offline
                              Mike Hankey
                              wrote on last edited by
                              #16

                              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

                              1 Reply Last reply
                              0
                              • R Roger Wright

                                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.

                                E Offline
                                E Offline
                                Espen Harlinn
                                wrote on last edited by
                                #17

                                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

                                L 1 Reply Last reply
                                0
                                • R Roger Wright

                                  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.

                                  M Offline
                                  M Offline
                                  Marc Clifton
                                  wrote on last edited by
                                  #18

                                  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

                                  My Blog
                                  Computational Types in C# and F#

                                  L 1 Reply Last reply
                                  0
                                  • K Kenneth Haugland

                                    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[^]

                                    R Offline
                                    R Offline
                                    RugbyLeague
                                    wrote on last edited by
                                    #19

                                    Laziness - that's why I occasionally use them. I feel dirty afterwards.

                                    K 1 Reply Last reply
                                    0
                                    • R Roger Wright

                                      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.

                                      P Offline
                                      P Offline
                                      PIEBALDconsult
                                      wrote on last edited by
                                      #20

                                      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.

                                      L 1 Reply Last reply
                                      0
                                      • K Kenneth Haugland

                                        :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...

                                        J Offline
                                        J Offline
                                        jschell
                                        wrote on last edited by
                                        #21

                                        Kenneth Haugland wrote:

                                        witch you could send around without createing a class.

                                        It would still require a class instance.

                                        1 Reply Last reply
                                        0
                                        • L leppie

                                          Anonymous classes handle most of these cases and cleaner in my opinion. Who knows what Item0 and Item1 and Item2 is?

                                          IronScheme
                                          ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))

                                          J Offline
                                          J Offline
                                          jschell
                                          wrote on last edited by
                                          #22

                                          leppie wrote:

                                          Who knows what Item0 and Item1 and Item2 is?

                                          The Tuple is a generic type so that shouldn't be a problem.

                                          L 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups