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. double v. Double?

double v. Double?

Scheduled Pinned Locked Moved C#
question
8 Posts 6 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.
  • P Offline
    P Offline
    prrusa
    wrote on last edited by
    #1

    How do these differ? Besides color and case. Console.WriteLine(typeof(double).FullName); Console.WriteLine(typeof(Double).FullName); Both tell me it's a System.Double Thank you, Paul

    S E 2 Replies Last reply
    0
    • P prrusa

      How do these differ? Besides color and case. Console.WriteLine(typeof(double).FullName); Console.WriteLine(typeof(Double).FullName); Both tell me it's a System.Double Thank you, Paul

      S Offline
      S Offline
      Stanciu Vlad
      wrote on last edited by
      #2

      Actualy they both are the same thing. The base class is System.Double whitch is mapped (for many reasons) into the double type. This case is encountered at every standard variable type. Would you prefer to write in your code

      System.Double myDouble = new System.Double(10);

      Or is easier like this ?

      double myDouble = 10;

      :)

      protected internal static readonly ... and I wish the list could continue ...

      P 1 Reply Last reply
      0
      • S Stanciu Vlad

        Actualy they both are the same thing. The base class is System.Double whitch is mapped (for many reasons) into the double type. This case is encountered at every standard variable type. Would you prefer to write in your code

        System.Double myDouble = new System.Double(10);

        Or is easier like this ?

        double myDouble = 10;

        :)

        protected internal static readonly ... and I wish the list could continue ...

        P Offline
        P Offline
        prrusa
        wrote on last edited by
        #3

        Thank you...

        J 1 Reply Last reply
        0
        • P prrusa

          Thank you...

          J Offline
          J Offline
          Jon Sagara
          wrote on last edited by
          #4

          In addition to

          System.Double myDouble = new System.Double(10);

          You can also say

          Double myDouble = 10.0;

          Jon Sagara Look at him. He runs like a Welshman. Doesn't he run like a Welshman? Doesn't he? I think he runs like a Welshman. Sagara.org | Blog | My Articles

          1 Reply Last reply
          0
          • P prrusa

            How do these differ? Besides color and case. Console.WriteLine(typeof(double).FullName); Console.WriteLine(typeof(Double).FullName); Both tell me it's a System.Double Thank you, Paul

            E Offline
            E Offline
            Ed Poore
            wrote on last edited by
            #5

            Like Vlad said there are many reasons, the main is that, like C, int should always be mapped to the size appropriate for your processor. So on a 32-bit system this is 32 bits and on a 64 bit system it's 64 bits wide, so System.Int32 and System.Int64 respectively. float and double are done in the same way although I'm not sure what their standing is because to my knowledge float and double are defined by IEEE and doubles are 64 bits by definition. Anyone correct me if I'm wrong Ed

            G 1 Reply Last reply
            0
            • E Ed Poore

              Like Vlad said there are many reasons, the main is that, like C, int should always be mapped to the size appropriate for your processor. So on a 32-bit system this is 32 bits and on a 64 bit system it's 64 bits wide, so System.Int32 and System.Int64 respectively. float and double are done in the same way although I'm not sure what their standing is because to my knowledge float and double are defined by IEEE and doubles are 64 bits by definition. Anyone correct me if I'm wrong Ed

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              One might think that it would work like C, but it doesn't. In C# all the data types are defined with an exact size. The int data type is an alias for the System.Int32 data type, so it will always be 32 bits regardless of the system. MSDN: C# built-in types[^] --- b { font-weight: normal; }

              E T 2 Replies Last reply
              0
              • G Guffa

                One might think that it would work like C, but it doesn't. In C# all the data types are defined with an exact size. The int data type is an alias for the System.Int32 data type, so it will always be 32 bits regardless of the system. MSDN: C# built-in types[^] --- b { font-weight: normal; }

                E Offline
                E Offline
                Ed Poore
                wrote on last edited by
                #7

                Hmmm, so it's only there to save keystrokes. I still can't remember where I read that C# acts like C, maybe someone with a 64 bit dev system can check it out? Live and learn! :-O Ed

                1 Reply Last reply
                0
                • G Guffa

                  One might think that it would work like C, but it doesn't. In C# all the data types are defined with an exact size. The int data type is an alias for the System.Int32 data type, so it will always be 32 bits regardless of the system. MSDN: C# built-in types[^] --- b { font-weight: normal; }

                  T Offline
                  T Offline
                  turbochimp
                  wrote on last edited by
                  #8

                  I agree, there is a different conception of the shorthand 'int' between classic C and managed languages using the common type system, since the CTS doesn't consult the system on which it's compiled to see what size an integer should be. However that's not the same as saying 'int' will always represent a 32 bit integer. I think the idea is that if, say, 64 bit systems became the standard, 'int' might eventually map to Int64. Obviously, that would require a release of the framework (or at least the CTS), but the possibility definitely exists, and there are numerous warnings to that effect in the documentation. In such a case, source compiled using 'int' could take on a different meaning than code written using the (more explicit) 'Int32' under the updated type system. That said, do I typically fully qualify all of my integral type declarations? No, not really. Do I lay awake nights worrying about it? No, not really. :)

                  The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

                  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