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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. The Lounge
  3. No typedef in C# 2.0

No typedef in C# 2.0

Scheduled Pinned Locked Moved The Lounge
csharpquestion
28 Posts 13 Posters 10 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.
  • P Paul Selormey

    Generics != template in C++. Unlike the template the Generics is a runtime thing and typedef, I think will defeat this purpose since each typedef causes the compiler to exit a class, not object instance. This is my little knowledge of it. Best regards, Paul. Jesus Christ is LOVE! Please tell somebody.

    J Offline
    J Offline
    Jorgen Sigvardsson
    wrote on last edited by
    #8

    There's still typing involved with generics. If you try

    List<int> l = new List<double>();

    you will get the error

    error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<double>' to 'System.Collections.Generic.List<int>'

    No matter how you implement generics, you must make types out of them, considering the fact that .NET is strongly typed. A typedef would be merely an alias for a type, and should in my point of view, not be that hard to implement. Good music: In my rosary[^]

    1 Reply Last reply
    0
    • realJSOPR realJSOP

      C# != C++; ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      M Offline
      M Offline
      Matt Newman
      wrote on last edited by
      #9

      John Simmons / outlaw programmer wrote: C# != C++; :wtf: OMG are you serious?!?!?! I thought the # was just a cool way of drawing two +'s :rolleyes: Matt Newman
      Even the very best tools in the hands of an idiot will produce something of little or no value. - Chris Meech on Idiots

      M L 2 Replies Last reply
      0
      • M Matt Newman

        John Simmons / outlaw programmer wrote: C# != C++; :wtf: OMG are you serious?!?!?! I thought the # was just a cool way of drawing two +'s :rolleyes: Matt Newman
        Even the very best tools in the hands of an idiot will produce something of little or no value. - Chris Meech on Idiots

        M Offline
        M Offline
        Matt Gerrans
        wrote on last edited by
        #10

        Wouldn't it be C++++ in that case? :-D Matt Gerrans

        L 1 Reply Last reply
        0
        • A Alvaro Mendez

          I've been doing some work with generics in C# 2.0 and I have to say that I'm a bit dissapointed by the fact that typedef has been omitted from the language. I would like to do the equivalent of:

          namespace MyNamespace
          {
          public typedef MyGenericClass<Class1, Class2, Class3, ...> MySimplerName;
          }

          I know about the using statement, but it only works on the current file. I would have to repeat it in every file! The only workaround is to derive the new class. However, since the constructors are not inherited, I would have to redefine them:

          namespace MyNamespace
          {
          public MySimplerName : MyGenericClass<Class1, Class2, Class3, ...>
          {
          public MySimplerName(Class1 c1) :
          base(c1)
          {
          }

            public MySimplerName(Class1 c1, Class2 c2) : 
               base(c1, c2) 
            { 
            }
          

          }
          }

          Seems like a hassle to me, which the typedef would have made unnecessary. Anyone have any insight as to why it was left out? Regards, Alvaro


          Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.

          N Offline
          N Offline
          Nemanja Trifunovic
          wrote on last edited by
          #11

          It is my understanding that one of the major goals of C# team is to keep their language relatively small and easy to learn, even at the price of omitting some useful and powerful features.


          My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

          1 Reply Last reply
          0
          • M Matt Newman

            John Simmons / outlaw programmer wrote: C# != C++; :wtf: OMG are you serious?!?!?! I thought the # was just a cool way of drawing two +'s :rolleyes: Matt Newman
            Even the very best tools in the hands of an idiot will produce something of little or no value. - Chris Meech on Idiots

            L Offline
            L Offline
            Long Gone
            wrote on last edited by
            #12

            Matt Newman wrote: OMG are you serious?!?!?! I thought the # was just a cool way of drawing two +'s :laugh: Don't shoot! I'm only the piano player messenger. Beatress

            1 Reply Last reply
            0
            • M Matt Gerrans

              Wouldn't it be C++++ in that case? :-D Matt Gerrans

              L Offline
              L Offline
              Long Gone
              wrote on last edited by
              #13

              Matt Gerrans wrote: Wouldn't it be C++++ in that case? Only if you write C## Don't shoot! I'm only the piano player messenger. Beatress

              M 1 Reply Last reply
              0
              • L Long Gone

                Matt Gerrans wrote: Wouldn't it be C++++ in that case? Only if you write C## Don't shoot! I'm only the piano player messenger. Beatress

                M Offline
                M Offline
                Matt Gerrans
                wrote on last edited by
                #14

                Look more closely. Matt Gerrans

                L 1 Reply Last reply
                0
                • A Alvaro Mendez

                  I've been doing some work with generics in C# 2.0 and I have to say that I'm a bit dissapointed by the fact that typedef has been omitted from the language. I would like to do the equivalent of:

                  namespace MyNamespace
                  {
                  public typedef MyGenericClass<Class1, Class2, Class3, ...> MySimplerName;
                  }

                  I know about the using statement, but it only works on the current file. I would have to repeat it in every file! The only workaround is to derive the new class. However, since the constructors are not inherited, I would have to redefine them:

                  namespace MyNamespace
                  {
                  public MySimplerName : MyGenericClass<Class1, Class2, Class3, ...>
                  {
                  public MySimplerName(Class1 c1) :
                  base(c1)
                  {
                  }

                    public MySimplerName(Class1 c1, Class2 c2) : 
                       base(c1, c2) 
                    { 
                    }
                  

                  }
                  }

                  Seems like a hassle to me, which the typedef would have made unnecessary. Anyone have any insight as to why it was left out? Regards, Alvaro


                  Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.

                  R Offline
                  R Offline
                  Rei Miyasaka
                  wrote on last edited by
                  #15

                  Remember in the Windows API how when you hunt through the jumble of typedefs and #defines, ints and HANDLEs and DWORDs and FAR and a bunch of other stuff turn to be the same thing? Or how MessageBox() and MessageBoxA() and _MessageBox() and __MessageBox() were all the same thing? I think the goal is to discourage that sort of thing. It'd be easy to use but it'd also be easier to abuse. Integrity is a key design objective in .NET.

                  V E 2 Replies Last reply
                  0
                  • J Jorgen Sigvardsson

                    And...? Good music: In my rosary[^]

                    P Offline
                    P Offline
                    Paul Selormey
                    wrote on last edited by
                    #16

                    typedef will be misleading. Anytime you do List<int> in C++, the compiler generates a class for you at compile time. The typedef in C++ is simply doing what the compiler will be doing anyway, but giving the generated class of the type List<int> a name you can remember. The Generics is designed to avoid the compile time class emitting, so throwing in a typedef will give a wrong image. This my understanding of the Generics concept and why it is maintained like that in MC++/CLR-C++ along side templates. Best regards, Paul. Jesus Christ is LOVE! Please tell somebody.

                    1 Reply Last reply
                    0
                    • M Matt Gerrans

                      Look more closely. Matt Gerrans

                      L Offline
                      L Offline
                      Long Gone
                      wrote on last edited by
                      #17

                      Matt Newman wrote: I thought the # was just a cool way of drawing two +'s # => ++ so ## => ++++ Matt Gerrans wrote: Look more closely. Obviously I am missing something. P.S. – for all you anal retentive folks out there tempted to comment on my spelling or grammar save your energy. I don’t care. Don't shoot! I'm only the piano player messenger. Beatress

                      M 1 Reply Last reply
                      0
                      • R Rei Miyasaka

                        Remember in the Windows API how when you hunt through the jumble of typedefs and #defines, ints and HANDLEs and DWORDs and FAR and a bunch of other stuff turn to be the same thing? Or how MessageBox() and MessageBoxA() and _MessageBox() and __MessageBox() were all the same thing? I think the goal is to discourage that sort of thing. It'd be easy to use but it'd also be easier to abuse. Integrity is a key design objective in .NET.

                        V Offline
                        V Offline
                        Vagif Abilov
                        wrote on last edited by
                        #18

                        Agree. How many various 32-bit types will we find in Win SDK headers. I guess several hundred. Вагиф Абилов MCP (Visual C++) Oslo, Norway If you're in a war, instead of throwing a hand grenade at the enemy, throw one of those small pumpkins. Maybe it'll make everyone think how stupid war is, and while they are thinking, you can throw a real grenade at them. Jack Handey.

                        J 1 Reply Last reply
                        0
                        • L Long Gone

                          Matt Newman wrote: I thought the # was just a cool way of drawing two +'s # => ++ so ## => ++++ Matt Gerrans wrote: Look more closely. Obviously I am missing something. P.S. – for all you anal retentive folks out there tempted to comment on my spelling or grammar save your energy. I don’t care. Don't shoot! I'm only the piano player messenger. Beatress

                          M Offline
                          M Offline
                          Matt Gerrans
                          wrote on last edited by
                          #19

                          Obviously:

                          # == ++ == ++++
                          ++

                          QED ;P Matt Gerrans

                          R L 2 Replies Last reply
                          0
                          • M Matt Gerrans

                            Obviously:

                            # == ++ == ++++
                            ++

                            QED ;P Matt Gerrans

                            R Offline
                            R Offline
                            Rei Miyasaka
                            wrote on last edited by
                            #20

                            Or you can take 2 +s, extend the lines and arrange them diagonally:

                            | | | |
                            -+--- | -+--+-
                            | + | = | |
                            | ---+- -+--+-
                            | | | |

                            M 1 Reply Last reply
                            0
                            • R Rei Miyasaka

                              Or you can take 2 +s, extend the lines and arrange them diagonally:

                              | | | |
                              -+--- | -+--+-
                              | + | = | |
                              | ---+- -+--+-
                              | | | |

                              M Offline
                              M Offline
                              Matt Gerrans
                              wrote on last edited by
                              #21

                              Two distorted +'s perhaps. Matt Gerrans

                              R 1 Reply Last reply
                              0
                              • M Matt Gerrans

                                Two distorted +'s perhaps. Matt Gerrans

                                R Offline
                                R Offline
                                Rei Miyasaka
                                wrote on last edited by
                                #22

                                :)

                                1 Reply Last reply
                                0
                                • A Alvaro Mendez

                                  I've been doing some work with generics in C# 2.0 and I have to say that I'm a bit dissapointed by the fact that typedef has been omitted from the language. I would like to do the equivalent of:

                                  namespace MyNamespace
                                  {
                                  public typedef MyGenericClass<Class1, Class2, Class3, ...> MySimplerName;
                                  }

                                  I know about the using statement, but it only works on the current file. I would have to repeat it in every file! The only workaround is to derive the new class. However, since the constructors are not inherited, I would have to redefine them:

                                  namespace MyNamespace
                                  {
                                  public MySimplerName : MyGenericClass<Class1, Class2, Class3, ...>
                                  {
                                  public MySimplerName(Class1 c1) :
                                  base(c1)
                                  {
                                  }

                                    public MySimplerName(Class1 c1, Class2 c2) : 
                                       base(c1, c2) 
                                    { 
                                    }
                                  

                                  }
                                  }

                                  Seems like a hassle to me, which the typedef would have made unnecessary. Anyone have any insight as to why it was left out? Regards, Alvaro


                                  Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.

                                  G Offline
                                  G Offline
                                  Giles
                                  wrote on last edited by
                                  #23

                                  I could see how that would be very useful, and help clean up code readability. Something I take for granted in C++, and don't think about. Personally, I would quite like a preprocessor as well.

                                  1 Reply Last reply
                                  0
                                  • R Rei Miyasaka

                                    Remember in the Windows API how when you hunt through the jumble of typedefs and #defines, ints and HANDLEs and DWORDs and FAR and a bunch of other stuff turn to be the same thing? Or how MessageBox() and MessageBoxA() and _MessageBox() and __MessageBox() were all the same thing? I think the goal is to discourage that sort of thing. It'd be easy to use but it'd also be easier to abuse. Integrity is a key design objective in .NET.

                                    E Offline
                                    E Offline
                                    Emilio Garavaglia
                                    wrote on last edited by
                                    #24

                                    "Interity" or "Integralism"? What's the matter with a type name redefinition for my own use, if it is closed in my own namespace? The (ab)use of type redefinition in Win32 derived from the fact that it was designed in flat namespace environment (plain C). All the consideration about templates and generics are correct, but the idea to alias a frequently used name dosn't semm to me so peregrine. My opinion is that ... they simply forgot it. And we are trying to justify them by "inventing" forcing anyone to use "patterns" also when not the case. And calling this "intrgrity". Did The "goto" history, blamed by zealots and rewed recently, teach anything ?? 2 bugs found. > recompile ... 65534 bugs found. :doh:

                                    1 Reply Last reply
                                    0
                                    • M Matt Gerrans

                                      Obviously:

                                      # == ++ == ++++
                                      ++

                                      QED ;P Matt Gerrans

                                      L Offline
                                      L Offline
                                      Long Gone
                                      wrote on last edited by
                                      #25

                                      Good one!:) P.S. – for all you anal retentive folks out there tempted to comment on my spelling or grammar save your energy. I don’t care. Don't shoot! I'm only the piano player messenger. Beatress

                                      1 Reply Last reply
                                      0
                                      • V Vagif Abilov

                                        Agree. How many various 32-bit types will we find in Win SDK headers. I guess several hundred. Вагиф Абилов MCP (Visual C++) Oslo, Norway If you're in a war, instead of throwing a hand grenade at the enemy, throw one of those small pumpkins. Maybe it'll make everyone think how stupid war is, and while they are thinking, you can throw a real grenade at them. Jack Handey.

                                        J Offline
                                        J Offline
                                        Jorgen Sigvardsson
                                        wrote on last edited by
                                        #26

                                        The thing is though that we ain't supposed to know that they're 32 bits wide.. ;P Good music: In my rosary[^]

                                        1 Reply Last reply
                                        0
                                        • A Alvaro Mendez

                                          I've been doing some work with generics in C# 2.0 and I have to say that I'm a bit dissapointed by the fact that typedef has been omitted from the language. I would like to do the equivalent of:

                                          namespace MyNamespace
                                          {
                                          public typedef MyGenericClass<Class1, Class2, Class3, ...> MySimplerName;
                                          }

                                          I know about the using statement, but it only works on the current file. I would have to repeat it in every file! The only workaround is to derive the new class. However, since the constructors are not inherited, I would have to redefine them:

                                          namespace MyNamespace
                                          {
                                          public MySimplerName : MyGenericClass<Class1, Class2, Class3, ...>
                                          {
                                          public MySimplerName(Class1 c1) :
                                          base(c1)
                                          {
                                          }

                                            public MySimplerName(Class1 c1, Class2 c2) : 
                                               base(c1, c2) 
                                            { 
                                            }
                                          

                                          }
                                          }

                                          Seems like a hassle to me, which the typedef would have made unnecessary. Anyone have any insight as to why it was left out? Regards, Alvaro


                                          Victory means exit strategy, and it's important for the President to explain to us what the exit strategy is. -- GWB, 1999.

                                          D Offline
                                          D Offline
                                          Daniel Grunwald
                                          wrote on last edited by
                                          #27

                                          It's called using, not typedef: using StringPair = System.Collections.Generic.KeyValuePair<string, string>;

                                          A 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