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. Other Discussions
  3. The Weird and The Wonderful
  4. typeof(string)? Meh.

typeof(string)? Meh.

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpvisual-studiocomgraphicsperformance
15 Posts 8 Posters 2 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.
  • D DavidNohejl

    Why, when you can write it like this:

    column.DataType = System.Type.GetType("System.String");
    

    :sigh: (obviously, it's C#)


    [My Blog]
    "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
    "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

    P Offline
    P Offline
    PaulPrice
    wrote on last edited by
    #6

    I dont get the question, call me stupid if you will!

    D P 2 Replies Last reply
    0
    • P PaulPrice

      I dont get the question, call me stupid if you will!

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #7

      column.DataType = System.Type.GetType("System.String"); column.DataType = typeof(string); Second line is more readable (IMO), less typing, and faster. There is absolutely no sane reason to write it the first way, hence my (not really a) question. :)


      [My Blog]
      "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
      "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

      P V 2 Replies Last reply
      0
      • P PIEBALDconsult

        It's a win/win/win.

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #8

        PIEBALDconsult wrote:

        It's a win/win/win

        And those are very nice situations to be in :rolleyes:

        "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

        1 Reply Last reply
        0
        • P PaulPrice

          I dont get the question, call me stupid if you will!

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #9

          It is not really a question, it is a programming horror the OP ran across.

          "Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus

          1 Reply Last reply
          0
          • D DavidNohejl

            column.DataType = System.Type.GetType("System.String"); column.DataType = typeof(string); Second line is more readable (IMO), less typing, and faster. There is absolutely no sane reason to write it the first way, hence my (not really a) question. :)


            [My Blog]
            "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
            "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

            P Offline
            P Offline
            PaulPrice
            wrote on last edited by
            #10

            ahhha, now I understand

            1 Reply Last reply
            0
            • D DavidNohejl

              Why, when you can write it like this:

              column.DataType = System.Type.GetType("System.String");
              

              :sigh: (obviously, it's C#)


              [My Blog]
              "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
              "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

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

              System.String might not be defined in the current scope (reasons why, god knows)! Then typeof() wont work :)

              1 Reply Last reply
              0
              • D DavidNohejl

                Why, when you can write it like this:

                column.DataType = System.Type.GetType("System.String");
                

                :sigh: (obviously, it's C#)


                [My Blog]
                "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
                "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                V Offline
                V Offline
                Vasudevan Deepak Kumar
                wrote on last edited by
                #12

                GetType() takes more time because of its runtime evaluation right?

                Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                D 1 Reply Last reply
                0
                • D DavidNohejl

                  column.DataType = System.Type.GetType("System.String"); column.DataType = typeof(string); Second line is more readable (IMO), less typing, and faster. There is absolutely no sane reason to write it the first way, hence my (not really a) question. :)


                  [My Blog]
                  "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
                  "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                  V Offline
                  V Offline
                  Vasudevan Deepak Kumar
                  wrote on last edited by
                  #13

                  dnh wrote:

                  less typing, and faster

                  And relatively less bytes to save on disk and less data to transfer across the wire during FTP and other copy operations. :-D

                  Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                  1 Reply Last reply
                  0
                  • V Vasudevan Deepak Kumar

                    GetType() takes more time because of its runtime evaluation right?

                    Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                    D Offline
                    D Offline
                    DavidNohejl
                    wrote on last edited by
                    #14

                    They are both in run time but there are JIT optimalizations... I've just found more on this topic in this[^] blog post.


                    [My Blog]
                    "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
                    "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                    1 Reply Last reply
                    0
                    • D DavidNohejl

                      PIEBALDconsult wrote:

                      ecause it's faster... much faster.

                      PIEBALDconsult wrote:

                      GetType took 00:00:17.1290068

                      PIEBALDconsult wrote:

                      typeof took a mere 00:00:00.0245439.

                      Either you missed my sarcasm, or I missed something else. So not only typeof shows intention much better (and is shorter), it's also faster. Excellent.


                      [My Blog]
                      "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
                      "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe

                      D Offline
                      D Offline
                      dojohansen
                      wrote on last edited by
                      #15

                      I believe the typeof(T) operator is resolved at compile-time. Thus when you speak of how long "typeof took" you are really only measuring the time spent to loop, increment and check loop variable, and perform the assignment. The MSDN documentation does make a distinction between types in general and the type objects that represent types (and which are, of course, themselves types). For example, the reference for the typeof() operator mentions: Used to obtain the System.Type object for a type. A typeof expression takes the following form: System.Type type = typeof(int); It's clear that the System.Type is the "metatype", the type that is created for us but describes a type we created. It also says to use GetType() to obtain the run-time type of an expression (although not the GetType overload discussed here, taking a string and finding a corresponding type in any loaded assembly in the appdomain!), and I take this as evidence in support of the "typeof() is resolved at compile-time" hypothesis. :)

                      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