Beginner vb.net, sum up ByVal and ByRef
1 pass through the ByVal variables, VB. NET duplicates a new variable that is equal to the source value. And ByRef is the equivalent of a reference.
For example, when we learn C, we get the swap () function
Imports System
' Test that Can ' t Swap A and B
Class MyApp
Public Shared Sub Main ()
Dim A as Integer = 0
Dim B as
What is the difference between Byval and byref in VB? To put it simply, Byval is the value passing, byref is the address passing, and ByVal: indicates that this parameter is passed by value. ByRef: this parameter is passed as a reference. The following section describes the differences between
ByVal is transmitted by value , the original value is not changed during the pass, and only a copy is transmitted.Instead of ByRef , the latter is the same memory address from the memory address.ByVal and ByRef (default value)These two are the parameters passed by the child procedure when the parameters are passed by the specifiedByVal (passed by value)ByRef (delivered by address)See the following example for details:Dim A as integer,b as IntegerA=1b=
What is the difference between ByVal and ByRef in VB? In short, ByVal is the value, ByRef is the address, ByVal: Indicates that the parameter is passed by value. ByRef: Indicates that the parameter is passed by reference. The following green Tea Small series for you to introduce the difference between
This code has only one difference from the previous code, that is, the transfer of the parameter I in the Add process was modified by ByVal to ByRef, but the result of the operation would be completely different, the MsgBox dialog box, and finally the result would be 4.
Through the above two codes, do we have a better understanding of the two parameters of ByVal and ByRef?
Attention mattersWort
the Internet has led to the use of several GB of resources. Whether or not you have to make up your mind to learn the pointer technology "sunflower Collection", it is always helpful to understand this effort.Note: In VB, the official website does not encourage the use of pointer. you do not expect to obtain official technical support for anything mentioned in this Article. Everything depends on our own efforts, everything is even more exciting!Let's
,
' is delivered by address, so modifying the No in ADD2 will cause
The value of the ' source parameter a ' is also modified.
End Sub
——————————————————————————————————————
3, ByVal and ByRef
ByVal the value of the parameter passed by ByRef, and the address of the parameter that is passed. Here, we do not have to distinguish between the transfer of pointers/address/reference to the different, in
1. ByVal value: A way to pass a parameter value instead of the address to a procedure, which makes the procedure accessible to a copy of the variable. As a result, the process cannot change the true value of the variable.2. ByRef value: A way to pass a parameter address instead of a value to a procedure, which allows the procedure to access the actual variable. As a result, the process can change the true value of the variable. Unless otherwise stated
For a long time in VB6, parameters are transmitted by ByRef by default, that is, transmitted by address)In. Net (C #, VB. Net), parameters are transmitted by ByVal (that is, by value) by default.During the optimization program these days, it is found that the default method (ByVal) is quite inefficient when large variables are transferred.For example, the input p
1. byval value transfer: A method of passing the parameter value instead of the address to the process. This allows the process to access the copy of the variable. As a result, the true positive value of the variable cannot be changed during the process.2. byref value passing: a parameter address instead of passing the value to the process. This allows the process to access the actual variables. As a result, the real positive value of the variable can
VB. NET transmits values by type or by reference, (byval byref) C # has an out.
Sometimes I will ask a small question during the interview. Hey hey, check if you are familiar with C # basic syntax.
For example
Public void XXX (byval form as form)
And
Public void XXX (byref form as form)
What is the difference? In fact, it is very simple to correspond
This article describes the importance of using byref/byval under. Net, and friends who need it can refer to
All along, in VB6, parameters are routed by ByRef (that is, delivered by address).Under. Net (c#,vb.net), parameters are routed by default using ByVal (that is, by value) and have not been noticed.These days the optimizer found that using the default method (ByVa
All along, in VB6, parameters are routed by ByRef (that is, delivered by address).
Under. Net (c#,vb.net), parameters are routed by default using ByVal (that is, by value) and have not been noticed.
These days the optimizer found that using the default method (ByVal) is quite inefficient when transferring large variables
such as the incoming parameter variable type is a large string, array, collection, Data
Differences:
Byval is used to pass a value. The real parameter and the form parameter have different memory units, so they do not interfere with each other!
Byref transfer address. The real parameter and the form parameter occupy the same memory unit. If the form parameter is changed, the real parameter is changed !!!!!!
Easy to understand:
Byval is gone forever
Byref may be updated!
In javascript:
Boolean,
Use byval and byref
Byval only transmits parameters.If byref defines a parameter pointing to it, it will pass the value back.Not very clear!
In Visual Basic, you can specify keywords by specifyingByvalOrByref, Pass the parameter to the process by value or by reference. Passing parameters through values means that the process cannot be calledCodeModify the content of the basic variable element of the par
For the question of "whether JavaScript function parameters are value passing (byVal) or address passing (byRef)", there is a common misunderstanding that "simple type" such as number and string is value passing, Number, string, Object, Array, and other "complex types" are data transfer addresses.Isn't that true? Why is there such a misunderstanding? Let's take a look at the two codes:Copy codeThe Code is as follows:// Code that creates the illusion o
depends on our own efforts, everything is even more exciting!Let's start a magical VB pointer adventure!
2. Let's see what the pointer can do? What is the purpose?Let's look at two programs. The functions of the program are to exchange two strings:[Procedure 1]: Note: standard practice swapstrSub swapstr (SA as string, Sb as string)Dim stmp as stringStmp = sa: SA = SB: SB = stmpEnd sub[Procedure 2]: Note: swapptr with pointerPrivate declare sub copym
Difference
All along, in VB6, parameters are routed by ByRef (that is, delivered by address).
Under. Net (c#,vb.net), parameters are routed by default using ByVal (that is, by value) and have not been noticed.
These days the optimizer found that using the default method (ByVal) is quite inefficient when transferring large variables
such as the incoming parameter variable type is a large string, array, colle
This article mainly introduces the misunderstanding of whether the function parameter in JS is to pass the value (byVal) or to transfer the address (byRef). We will explain through examples, if you have any need, you can refer to the common misunderstanding of "whether JavaScript function parameters are byVal or byRef": number, string and other "simple types" are values, Number, String, Object, Array, and o
For the question of "whether JavaScript function parameters are value passing (byval) or address passing (byref)", there is a common misunderstanding that "simple type" such as number and string is value passing, number, string, object, array, and other "complex types" are data transfer addresses.Isn't that true? Why is there such a misunderstanding? Take a look at the two paragraphsCode:
//Code that creates the illusion of passing valuesFunctionMod
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.