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. Visual Basic
  4. difference between these code

difference between these code

Scheduled Pinned Locked Moved Visual Basic
csharpjsonquestion
7 Posts 4 Posters 1 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.
  • Y Offline
    Y Offline
    yuifox
    wrote on last edited by
    #1

    Hi, I'm new in vb.net What the difference of these codes

    for u = 0 to datatable.rows.count - 1
    ' process code
    next

    for each rows in datatable.rows
    ' process code
    next

    assuming process code are to parsing data datatable.rows either to search or to print or to calculate. which one is faster ? can someone give me some enlighment ? sorry for bad english.

    D P S 3 Replies Last reply
    0
    • Y yuifox

      Hi, I'm new in vb.net What the difference of these codes

      for u = 0 to datatable.rows.count - 1
      ' process code
      next

      for each rows in datatable.rows
      ' process code
      next

      assuming process code are to parsing data datatable.rows either to search or to print or to calculate. which one is faster ? can someone give me some enlighment ? sorry for bad english.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      One loop is an indexer and the other is an enumator. Indexers can modify the collection while you're iterating over it while enumators cannot. Indexers are a little faster than enumerators, but also require you to know more about the size and types the array holds.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      Y 1 Reply Last reply
      0
      • Y yuifox

        Hi, I'm new in vb.net What the difference of these codes

        for u = 0 to datatable.rows.count - 1
        ' process code
        next

        for each rows in datatable.rows
        ' process code
        next

        assuming process code are to parsing data datatable.rows either to search or to print or to calculate. which one is faster ? can someone give me some enlighment ? sorry for bad english.

        P Offline
        P Offline
        Pravin Patil Mumbai
        wrote on last edited by
        #3

        Just to add to Dave's comment - The for-loop is faster than the foreach-loop if the array must only be accessed once per iteration. (More Details with Benchmark Test[^]).

        If you can dream it, You can do it. Explore My School

        Y 1 Reply Last reply
        0
        • D Dave Kreskowiak

          One loop is an indexer and the other is an enumator. Indexers can modify the collection while you're iterating over it while enumators cannot. Indexers are a little faster than enumerators, but also require you to know more about the size and types the array holds.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          Y Offline
          Y Offline
          yuifox
          wrote on last edited by
          #4

          Thank You Dave. It clear my mind.

          1 Reply Last reply
          0
          • P Pravin Patil Mumbai

            Just to add to Dave's comment - The for-loop is faster than the foreach-loop if the array must only be accessed once per iteration. (More Details with Benchmark Test[^]).

            If you can dream it, You can do it. Explore My School

            Y Offline
            Y Offline
            yuifox
            wrote on last edited by
            #5

            Thank you Pravin for the link. It gives me an understanding.

            P 1 Reply Last reply
            0
            • Y yuifox

              Thank you Pravin for the link. It gives me an understanding.

              P Offline
              P Offline
              Pravin Patil Mumbai
              wrote on last edited by
              #6

              My pleasure yuifox... Happy coding ;)

              If you can dream it, You can do it. Explore My School - Schools In India

              1 Reply Last reply
              0
              • Y yuifox

                Hi, I'm new in vb.net What the difference of these codes

                for u = 0 to datatable.rows.count - 1
                ' process code
                next

                for each rows in datatable.rows
                ' process code
                next

                assuming process code are to parsing data datatable.rows either to search or to print or to calculate. which one is faster ? can someone give me some enlighment ? sorry for bad english.

                S Offline
                S Offline
                SoyDesarrollador net
                wrote on last edited by
                #7

                El segundo código es mas eficiente y rapido.

                _______________________ Edward J. Ocando. | Desarrollador | SoyDesarrollador.net Telefono. +58 (416) 164.34.88 | Edward.Ocando@soydesarrollador.net

                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