|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
default in .NET byref or byval?In 6, by default arguments, were passed byref what is the default in .NET?
Can you point me to any MSDN documentation? TIA In VB.Net, the arguments in the function/sub are assumed as ByVal unless
explicitly mentioned as ByRef. If you open a VB project under VB.Net and create a function/sub and only specify argument type and name. After you save the project you should see that the 'ByVal' has been added to argument. Regards Sanjib Show quoteHide quote "prefersgolfing" <pregfersgolf***@hotmail.com> wrote in message news:eBo0tmTmGHA.492@TK2MSFTNGP05.phx.gbl... > In 6, by default arguments, were passed byref what is the default in .NET? > Can you point me to any MSDN documentation? TIA > Default is ByVal. See the Remarks (Rules) section here:
http://msdn2.microsoft.com/en-us/library/cbs7z96t.aspx /claes Show quoteHide quote "prefersgolfing" <pregfersgolf***@hotmail.com> wrote in message news:eBo0tmTmGHA.492@TK2MSFTNGP05.phx.gbl... > In 6, by default arguments, were passed byref what is the default in .NET? > Can you point me to any MSDN documentation? TIA > Be careful when passing reference type arguments like a Class By Value. It's
a little confusing but when these arguments are passed by Value, actually only a pointer to the argument will be passed and if you change any of the Class's properties in the sub/funciton, the change will be reflected in the calling program's instance of the class. -- Show quoteHide quoteDennis in Houston "prefersgolfing" wrote: > In 6, by default arguments, were passed byref what is the default in .NET? > Can you point me to any MSDN documentation? TIA > > > That is incorrect. When you pass a reference type ByVal, a pointer to a copy
of the data gets passed to the method. You can manipulate the data as much as you want with out affecting the value of the data from the calling method. When you pass a reference type ByRef, you are actually passing the pointer to that value to the method. If you manipulate the value within the method, the value is also affected in the calling method. Public Sub Test() Dim x As Integer = 10 PassingByVal(x) Console.WriteLine(x) ' value of x = 10 PassingByRef(x) Console.WriteLine(x) 'value of x = 100 End Sub Public Sub PassingByVal(ByVal x As integer) x = x * 2 End Sub Public Sub PassingByRef(ByRef x as Integer) x = x * 2 End Sub Show quoteHide quote "Dennis" wrote: > Be careful when passing reference type arguments like a Class By Value. It's > a little confusing but when these arguments are passed by Value, actually > only a pointer to the argument will be passed and if you change any of the > Class's properties in the sub/funciton, the change will be reflected in the > calling program's instance of the class. > -- > Dennis in Houston > > > "prefersgolfing" wrote: > > > In 6, by default arguments, were passed byref what is the default in .NET? > > Can you point me to any MSDN documentation? TIA > > > > > > Hello, rmacias,
Actually, I think that Dennis has it right. If passed ByVal the object passed cannot be replaced by a different object in the routine being called. However the called routine can modify the properties of the object passed, and these changes will be reflected in the object referenced in the calling routine. If passed ByRef, the object itself can be replaced, so that when the routine called returns, the reference passed might refer to an entirely different object than that which was passed in. Cheers, Randy rmacias wrote: Show quoteHide quote > That is incorrect. When you pass a reference type ByVal, a pointer to a copy > of the data gets passed to the method. You can manipulate the data as much > as you want with out affecting the value of the data from the calling method. > > When you pass a reference type ByRef, you are actually passing the pointer > to that value to the method. If you manipulate the value within the method, > the value is also affected in the calling method. > > Public Sub Test() > > Dim x As Integer = 10 > > PassingByVal(x) > Console.WriteLine(x) ' value of x = 10 > > PassingByRef(x) > Console.WriteLine(x) 'value of x = 100 > > End Sub > > Public Sub PassingByVal(ByVal x As integer) > x = x * 2 > End Sub > > Public Sub PassingByRef(ByRef x as Integer) > x = x * 2 > End Sub > > "Dennis" wrote: > > >>Be careful when passing reference type arguments like a Class By Value. It's >>a little confusing but when these arguments are passed by Value, actually >>only a pointer to the argument will be passed and if you change any of the >>Class's properties in the sub/funciton, the change will be reflected in the >>calling program's instance of the class. >>-- >>Dennis in Houston >> >> >>"prefersgolfing" wrote: >> >> >>>In 6, by default arguments, were passed byref what is the default in .NET? >>>Can you point me to any MSDN documentation? TIA >>> >>> >>> Rmacias,
In my idea incorrect. ByVal sends the reference to the Reference by ref.types and the Value by val.types (what is done by a copy of that) ByRef uses in both situations a copy of the reference (what is done by a copy of that). ByVal does mean as well that when you are handling data in a refernce type you are changing the actual object. Although it is not nice coding to use this way as the byval can used in a sub, it is nicer to use a function and return the object again, just for readability. Cor Show quoteHide quote "rmacias" <rmacias@newsgroup.nospam> schreef in bericht news:3CCB835F-0CE2-4A07-932D-994B8033E0F8@microsoft.com... > That is incorrect. When you pass a reference type ByVal, a pointer to a > copy > of the data gets passed to the method. You can manipulate the data as > much > as you want with out affecting the value of the data from the calling > method. > > When you pass a reference type ByRef, you are actually passing the pointer > to that value to the method. If you manipulate the value within the > method, > the value is also affected in the calling method. > > Public Sub Test() > > Dim x As Integer = 10 > > PassingByVal(x) > Console.WriteLine(x) ' value of x = 10 > > PassingByRef(x) > Console.WriteLine(x) 'value of x = 100 > > End Sub > > Public Sub PassingByVal(ByVal x As integer) > x = x * 2 > End Sub > > Public Sub PassingByRef(ByRef x as Integer) > x = x * 2 > End Sub > > "Dennis" wrote: > >> Be careful when passing reference type arguments like a Class By Value. >> It's >> a little confusing but when these arguments are passed by Value, actually >> only a pointer to the argument will be passed and if you change any of >> the >> Class's properties in the sub/funciton, the change will be reflected in >> the >> calling program's instance of the class. >> -- >> Dennis in Houston >> >> >> "prefersgolfing" wrote: >> >> > In 6, by default arguments, were passed byref what is the default in >> > .NET? >> > Can you point me to any MSDN documentation? TIA >> > >> > >> > rmacias wrote:
> That is incorrect. When you pass a reference type ByVal, a pointer to a copy What you have written is about *VALUE* types, and is completely not> of the data gets passed to the method. You can manipulate the data as much > as you want with out affecting the value of the data from the calling method. > > When you pass a reference type ByRef, you are actually passing the pointer > to that value to the method. If you manipulate the value within the method, > the value is also affected in the calling method. true for reference types. > Integer is a *VALUE* type.> Public Sub Test() > > Dim x As Integer = 10 Show quoteHide quote > > PassingByVal(x) > Console.WriteLine(x) ' value of x = 10 > > PassingByRef(x) > Console.WriteLine(x) 'value of x = 100 > > End Sub > > Public Sub PassingByVal(ByVal x As integer) > x = x * 2 > End Sub > > Public Sub PassingByRef(ByRef x as Integer) > x = x * 2 > End Sub -- Larry Lard Replies to group please
ASP.NET web application - date conversions UK date format?
Building a single EXE file in VB 2005? What errors are not trappable? Build Failed - 0 Errors Adding ActiveX controls at runtime and threading Define a compilation switch How to gain access to objet in different class ? Listbox help Dynamically Creating A CSS Class Merging workbooks |
|||||||||||||||||||||||