Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2006

Tip: Looking for answers? Try searching our database.

ByRef

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne Garvander - 28 Apr 2006 18:51 GMT
How do I pass a variable ByRef in C#?
Signature

Arne Garvander
Certified Geek

Barry Kelly - 28 Apr 2006 19:03 GMT
> How do I pass a variable ByRef in C#?

ref

as in:

void MyMethod(ref int x)
{
  x = 42;
}

-- Barry
Jon Skeet [C# MVP] - 28 Apr 2006 20:29 GMT
> How do I pass a variable ByRef in C#?

Using the "ref" modifier. Note that it's rarely necessary, as reference
type values are already references. (Those references are passed by
value, however.)

See http://www.pobox.com/~skeet/csharp/parameters.html for more
information.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Arne Garvander - 28 Apr 2006 20:42 GMT
Is a reference type value the same as an object?
Signature

Arne Garvander
(I program VB.Net for fun and C# to get paid.)

> > How do I pass a variable ByRef in C#?
>
[quoted text clipped - 4 lines]
> See http://www.pobox.com/~skeet/csharp/parameters.html for more
> information.
Jon Skeet [C# MVP] - 28 Apr 2006 20:56 GMT
> Is a reference type value the same as an object?

I expressed myself badly. When you have a variable whose type is a
reference type, the value of that variable is a reference. It's not the
object itself, it's a reference to the object. Suppose you had:

string x = "some very long string indeed which would be large etc";

then the value of x is just a reference - 4 or 8 bytes depending on
your platform. When you use x as an argument to a method, only 4 (or 8)
bytes are copied - the reference. The object itself is on the heap, and
the new copy of the reference points to the same object as the "old"
reference.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Barry Kelly - 28 Apr 2006 21:06 GMT
> Is a reference type value the same as an object?

Yes, anything declared with the 'class' keyword in C#.

-- Barry

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.