Re: Class vs. Struct - Newbie question & app.
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Sat, 26 Aug 2006 21:29:58 +0100
fidel <fiddyschmitt@xxxxxxxxx> wrote:
yep - if you create a struct and pass it to a function, it will be just
be a copy. so the function can modify it till it's heart's content, and
it wont affect the original struct.
Unless, of course, a member of the struct is a mutable reference
type... it's worth clarifying that when a struct value is copied, it's
only a shallow copy.
If you tried the same with a class though, you would be passing it "by
reference" so to speak, and therefore that method could modify it.
Note that it's not *really* passed by reference. That means something
different, and is available with the "ref" keyword.
See http://www.pobox.com/~skeet/csharp/parameters.html
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- References:
- Class vs. Struct - Newbie question & app.
- From: Russell
- Re: Class vs. Struct - Newbie question & app.
- From: fidel
- Class vs. Struct - Newbie question & app.
- Prev by Date: Re: lost in regular expression
- Next by Date: Virtual class methods
- Previous by thread: Re: Class vs. Struct - Newbie question & app.
- Next by thread: OleDbDataAdapter Fill Bug.
- Index(es):
Relevant Pages
|