RobLog

Web Design in the World of .NET (C# and VB.NET, XML, and Javascript). I learned how to program from TheDailyWTF.com!
posts - 140, comments - 129, trackbacks - 5

My Links

News

Main Site Cert Corner Goals About Me

Article Categories

Archives

Post Categories

Image Galleries

.NET

Personal

WOW


When passing a Reference Type "ByVal" ONLY the Reference to the object is passed "ByVal"

An article by Scott GreenBerger on GeeksWithBlogs points this out in a way that is easy to understand: http://www.geekswithblogs.net/sgreenberger/articles/ExaminingByVal.aspx 

As Scott pointed out, this means that if you pass the object by value (ByVal), ONLY the reference to it is passed by value.  That means if you pass an object Car (or in Scott's article a Beer Object :) ) to another procedure (or friend in this case) By Value, and the procedure executes car.Wreck(), the Car Object that you have passed by value will also be wrecked!   Easy enough to understand?  Yes, I had a little trouble wrapping my brain around this one at first until I read more of Scott's article.

Scott does a great job of explaining it in his article.

posted on Wednesday, December 29, 2004 12:31 AM

Feedback

# re: Reference Types Passed ByVal are actually passed ByRef

Just wanted to point out an important distinction here. When reference types are passed ByVal, *the reference is passed by value*. This is actually quite different than passing the object by reference, as the article hopefully demonstrates.
12/29/2004 8:36 AM | Scott Greenberger

# re: Reference Types Passed ByVal are actually passed ByRef

Thanks Scott. Let me change the title. :)
12/29/2004 8:39 PM | Robz

# re: When passing a Reference Type "ByVal" ONLY the Reference to the object is passed "ByVal"

Hmm, is there any use then in passing a reference type ByRef?

Is it perhaps possible to swap two reference type objects around by passing them both to a function byrefand assigning one to the other? (Using a temporary variable in the middle ofcourse)?
1/11/2005 2:48 PM | Drak

Post Comment

Title  
Name  
Url
Comment   
Protected by Clearscreen.SharpHIPEnter the code you see: