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. Nicer way to validate a value type out of System.Data.DataRow

Nicer way to validate a value type out of System.Data.DataRow

Scheduled Pinned Locked Moved C#
data-structurestutorialquestion
6 Posts 2 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.
  • M Offline
    M Offline
    Martin 0
    wrote on last edited by
    #1

    Hello everbody! Just looked threw my project and found code which I don't like at all. I'm having an instance of DataRow and go threw it in a loop. There I need to store the data for example in a double array. This is what I do now: if (myrow[x].GetType() == typeof(System.Double)) { doublearray[x]= (double)myrow[x]; } For reference types I would use the "as" operator! Is there a nicer way to do this? Thanks for suggestions! All the best, Martin

    P 1 Reply Last reply
    0
    • M Martin 0

      Hello everbody! Just looked threw my project and found code which I don't like at all. I'm having an instance of DataRow and go threw it in a loop. There I need to store the data for example in a double array. This is what I do now: if (myrow[x].GetType() == typeof(System.Double)) { doublearray[x]= (double)myrow[x]; } For reference types I would use the "as" operator! Is there a nicer way to do this? Thanks for suggestions! All the best, Martin

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

      **is** System.Double)
      (I rarely use as; I usually just cast.)

      M 1 Reply Last reply
      0
      • P PIEBALDconsult

        **is** System.Double)
        (I rarely use as; I usually just cast.)

        M Offline
        M Offline
        Martin 0
        wrote on last edited by
        #3

        Hello,

        PIEBALDconsult wrote:

        is System.Double)

        Does this compile? I thought it's (is and as) only working for reference type. All the best, Martin

        P 1 Reply Last reply
        0
        • M Martin 0

          Hello,

          PIEBALDconsult wrote:

          is System.Double)

          Does this compile? I thought it's (is and as) only working for reference type. All the best, Martin

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

          I use it.

          M 1 Reply Last reply
          0
          • P PIEBALDconsult

            I use it.

            M Offline
            M Offline
            Martin 0
            wrote on last edited by
            #5

            Hello, Sorry! Just tested it and found out that is also works with valuy types, but as only works with reference types. All the best, Martin

            P 1 Reply Last reply
            0
            • M Martin 0

              Hello, Sorry! Just tested it and found out that is also works with valuy types, but as only works with reference types. All the best, Martin

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

              It's better to try something even if you think it won't work.

              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