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. General Programming
  3. C#
  4. Int32 type alias problem!

Int32 type alias problem!

Scheduled Pinned Locked Moved C#
csharpc++helptutorialquestion
13 Posts 7 Posters 3 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.
  • J Judah Gabriel Himango

    using Integer = System.Int32;
    ...

    Integer i = 0;

    Keep in mind that the C# int keyword is an alias for System.Int32.

    Tech, life, family, faith: Give me a visit. I'm currently blogging about: Check out this cutie The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

    K Offline
    K Offline
    karam chandrabose
    wrote on last edited by
    #4

    hey Judah, thanks from me too! i thought aliasing we can do only for namespaces!!

    J 1 Reply Last reply
    0
    • K karam chandrabose

      hey Judah, thanks from me too! i thought aliasing we can do only for namespaces!!

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #5

      No, you can alias types, too. There is one caveat: unlike C/C++, aliases are per-file. Each file that wants to use the Integer alias described above would have to have to specify it in using declarations. They are especially useful with generics, IMO.

      using IntStringPair = System.Collections.Generic.KeyValuePair<int, string>;
      ...
      List<IntStringPair> listOfPairs = ...;

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Check out this cutie The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      C 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        No, you can alias types, too. There is one caveat: unlike C/C++, aliases are per-file. Each file that wants to use the Integer alias described above would have to have to specify it in using declarations. They are especially useful with generics, IMO.

        using IntStringPair = System.Collections.Generic.KeyValuePair<int, string>;
        ...
        List<IntStringPair> listOfPairs = ...;

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: Check out this cutie The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #6

        Judah Himango wrote:

        using IntStringPair = System.Collections.Generic.KeyValuePair;

        That's a shame, I hated when people did that in C++....

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        J CPalliniC L 3 Replies Last reply
        0
        • C Christian Graus

          Judah Himango wrote:

          using IntStringPair = System.Collections.Generic.KeyValuePair;

          That's a shame, I hated when people did that in C++....

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #7

          Heh, well, at least it's limited in scope. It's true, I always hate having to track down aliases in C++. Or worse, aliases of aliases of aliases...etc. I don't think you can do alias an alias in C#, which is good. Question is, is the aliasing worth it? Which one would you rather encounter:

          List<KeyValuePair<int, string>> listOfPairs = new List<KeyValuePair<int, string>>();
          foreach(KeyValuePair<int, string> pair in listOfPairs)
          {
          ...
          }

          or

          using IntStringPair = System.Collections.Generic.KeyValuePair<int, string>;

          ...

          List<IntStringPair> listOfPairs = new List<IntStringPair>();
          foreach(IntStringPair pair in listOfPairs)
          {
          ...
          }

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: Check out this cutie The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          C 1 Reply Last reply
          0
          • J Judah Gabriel Himango

            Heh, well, at least it's limited in scope. It's true, I always hate having to track down aliases in C++. Or worse, aliases of aliases of aliases...etc. I don't think you can do alias an alias in C#, which is good. Question is, is the aliasing worth it? Which one would you rather encounter:

            List<KeyValuePair<int, string>> listOfPairs = new List<KeyValuePair<int, string>>();
            foreach(KeyValuePair<int, string> pair in listOfPairs)
            {
            ...
            }

            or

            using IntStringPair = System.Collections.Generic.KeyValuePair<int, string>;

            ...

            List<IntStringPair> listOfPairs = new List<IntStringPair>();
            foreach(IntStringPair pair in listOfPairs)
            {
            ...
            }

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: Check out this cutie The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #8

            I'd prefer the former, because there's no question of what it is.  Actually, I would create a struct that names the int and string according to what they represent.

            Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

            J 1 Reply Last reply
            0
            • C Christian Graus

              Judah Himango wrote:

              using IntStringPair = System.Collections.Generic.KeyValuePair;

              That's a shame, I hated when people did that in C++....

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #9

              Christian Graus wrote:

              That's a shame, I hated when people did that in C++....

              I think they are useful, since you haven't to interpretate again and again complex expressions. Anyway it's a matter of taste.:)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • C Christian Graus

                Judah Himango wrote:

                using IntStringPair = System.Collections.Generic.KeyValuePair;

                That's a shame, I hated when people did that in C++....

                Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

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

                Christian Graus wrote:

                That's a shame, I hated when people did that in C++....

                That depends how! With a define or a typedef?

                **

                xacc.ide-0.2.0.57 - now with C# 2.0 parser and seamless VS2005 solution support!

                **

                1 Reply Last reply
                0
                • C Christian Graus

                  I'd prefer the former, because there's no question of what it is.  Actually, I would create a struct that names the int and string according to what they represent.

                  Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                  J Offline
                  J Offline
                  Judah Gabriel Himango
                  wrote on last edited by
                  #11

                  Interesting. I'd prefer the latter because it is descriptive enough by its name alone and it's easier on the eyes than the double generic type. But, I do see where you're coming from. Aliases are certainly open to abuse, albeit on a much smaller level than C++ #defines. Come to think of it, I can't say I've seen alias abuse in any project I've worked on, especially nothing so terrible as abominations like A Better C[^] or VB++[^]. :)

                  Tech, life, family, faith: Give me a visit. I'm currently blogging about: Check out this cutie The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                  C 1 Reply Last reply
                  0
                  • J Judah Gabriel Himango

                    Interesting. I'd prefer the latter because it is descriptive enough by its name alone and it's easier on the eyes than the double generic type. But, I do see where you're coming from. Aliases are certainly open to abuse, albeit on a much smaller level than C++ #defines. Come to think of it, I can't say I've seen alias abuse in any project I've worked on, especially nothing so terrible as abominations like A Better C[^] or VB++[^]. :)

                    Tech, life, family, faith: Give me a visit. I'm currently blogging about: Check out this cutie The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #12

                    I've worked on C++ projects where I was always going back to see what the typedefs meant.  I hated it.

                    Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                    S 1 Reply Last reply
                    0
                    • C Christian Graus

                      I've worked on C++ projects where I was always going back to see what the typedefs meant.  I hated it.

                      Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                      S Offline
                      S Offline
                      Scott Dorman
                      wrote on last edited by
                      #13

                      I agree with Chris. I've dealt with C++ projects where the developer went crazy with typedefs. Even though C# has a similar ability, it is much simpler to use the native data type names. They may not be as short as we want or as clear within the specific application domain, but they are unambigous and standard. I don't have to worry about a new developer trying to understand what an IntStringPair is, or look for it on MSDN. KeyValuePair clearly defines the object using terms that everyone is familar with.

                      ----------------------------- In just two days, tomorrow will be yesterday.

                      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