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. value and reference

value and reference

Scheduled Pinned Locked Moved Visual Basic
csharpquestion
5 Posts 3 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
    pankajgarg12
    wrote on last edited by
    #1

    What is the difference between byval and byref? What is the difference b/w c# and vb.net? Thank You Pankaj Garg -- modified at 3:34 Sunday 23rd April, 2006

    S 1 Reply Last reply
    0
    • P pankajgarg12

      What is the difference between byval and byref? What is the difference b/w c# and vb.net? Thank You Pankaj Garg -- modified at 3:34 Sunday 23rd April, 2006

      S Offline
      S Offline
      Steve Pullan
      wrote on last edited by
      #2

      pankajgarg12 wrote:

      What is the difference between byval and byref?

      Passing a variable to a Procedure or Function ByVal means that the actual value of the variable is placed on the stack. If you pass it ByRef, only a reference (i.e. pointer) to the variable will be placed on the stack. A ByRef will allow the called function to modify the actual source variable. A ByVal call never touches the original variable. Depending on the size of the variable and/or its purpose, you can use either in your own code. If you have a large array for example, it would be better to pass it as ByRef so that you don't put too much information on the stack.

      pankajgarg12 wrote:

      What is the difference b/w c# and vb.net?

      They are both programming languages. VB.NET's ancestor is Visual Basic, C#'s ancestry is from C and C++. Use whichever you are most familiar and comfortable. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-)

      J 1 Reply Last reply
      0
      • S Steve Pullan

        pankajgarg12 wrote:

        What is the difference between byval and byref?

        Passing a variable to a Procedure or Function ByVal means that the actual value of the variable is placed on the stack. If you pass it ByRef, only a reference (i.e. pointer) to the variable will be placed on the stack. A ByRef will allow the called function to modify the actual source variable. A ByVal call never touches the original variable. Depending on the size of the variable and/or its purpose, you can use either in your own code. If you have a large array for example, it would be better to pass it as ByRef so that you don't put too much information on the stack.

        pankajgarg12 wrote:

        What is the difference b/w c# and vb.net?

        They are both programming languages. VB.NET's ancestor is Visual Basic, C#'s ancestry is from C and C++. Use whichever you are most familiar and comfortable. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-)

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        Thanks for pointing out that passing by reference when you are dealing with large amounts of data is the way to go. I am going back to school after many years and the instructor said that passing by value is faster and more efficient. I do not want to tell the instructor (masters degree) that he does not know what he is talking about (grades are on the line), but that is a fact. By the way, I am going back to school because 15 years of experience does not qualify me to teach. INTP “Testing can show the presence of errors, but not their absence.” Edsger Dijkstra

        S 1 Reply Last reply
        0
        • J John R Shaw

          Thanks for pointing out that passing by reference when you are dealing with large amounts of data is the way to go. I am going back to school after many years and the instructor said that passing by value is faster and more efficient. I do not want to tell the instructor (masters degree) that he does not know what he is talking about (grades are on the line), but that is a fact. By the way, I am going back to school because 15 years of experience does not qualify me to teach. INTP “Testing can show the presence of errors, but not their absence.” Edsger Dijkstra

          S Offline
          S Offline
          Steve Pullan
          wrote on last edited by
          #4

          John R. Shaw wrote:

          the instructor said that passing by value is faster and more efficient.

          Well yes - it depends on the nature of the data that you are processing. For small data (e.g. a single Integer) then passing ByVal is fine. An array of 100 Integers or a 128kB image is a bit too much. One thing to keep in mind is that a ByVal parameter actually causes a COPY of that variable (Integer, Array, String etc...) to be made and placed onto the stack. A ByRef creates a pointer to the ORIGINAL variable so only one exists - and that's why ByRef variables can be modified by called functions, so you must be aware of this desired (or undesired) behaviour. It can cause program errors. As an aside - ByVal variables can also be modified by the called function, but you are only modifying the copy and not the original so any changes are lost when the function returns to its caller. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-)

          J 1 Reply Last reply
          0
          • S Steve Pullan

            John R. Shaw wrote:

            the instructor said that passing by value is faster and more efficient.

            Well yes - it depends on the nature of the data that you are processing. For small data (e.g. a single Integer) then passing ByVal is fine. An array of 100 Integers or a 128kB image is a bit too much. One thing to keep in mind is that a ByVal parameter actually causes a COPY of that variable (Integer, Array, String etc...) to be made and placed onto the stack. A ByRef creates a pointer to the ORIGINAL variable so only one exists - and that's why ByRef variables can be modified by called functions, so you must be aware of this desired (or undesired) behaviour. It can cause program errors. As an aside - ByVal variables can also be modified by the called function, but you are only modifying the copy and not the original so any changes are lost when the function returns to its caller. ...Steve 1. quod erat demonstrandum 2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once :-)

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            Thanks for the well written reply. I did not mean to give the impression that I did not know this already, just that the instructor made a blanket statement that is not always true. I have been writting software for many years and prefer C++, but I do not have a degree. The class I just finished taking yesterday was on programming in VB.Net. I expect my total score to be 993 out of a possible 1000, do to a minor disagreement with the instructor. :-O INTP “Testing can show the presence of errors, but not their absence.” Edsger Dijkstra

            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