Re: Class vs. Struct - Newbie question & app.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • [PATCH] w1: cleanups.
    ... you can redistribute it and/or modify ... it under the terms of the GNU General Public License as published by ... +static struct device_attribute w1_slave_attribute = ... int found = 0; ...
    (Linux-Kernel)
  • Re: [PATCH net-next-2.6 v2] can: Topcliff: PCH_CAN driver: Fix build warnings
    ... u32 cont; ... I suggest to make a struct defining a complete ... I will modify to a reserveX. ... unsigned int int_enables; ...
    (Linux-Kernel)
  • [PATCH 11/16] GFS: mount and tuning options
    ... * modify, copy, or redistribute it subject to the terms and conditions ... * of the GNU General Public License v.2. ... * display struct lm_lockstruct fields ...
    (Linux-Kernel)
  • [PATCH 12/16] GFS2: Mounting & sysfs interface
    ... * This copyrighted material is made available to anyone wishing to use, ... * modify, copy, or redistribute it subject to the terms and conditions ... * of the GNU General Public License v.2. ... * display struct lm_lockstruct fields ...
    (Linux-Kernel)
  • [PATCH 12/16] GFS2: Mounting & sysfs interface
    ... * This copyrighted material is made available to anyone wishing to use, ... * modify, copy, or redistribute it subject to the terms and conditions ... * of the GNU General Public License v.2. ... * display struct lm_lockstruct fields ...
    (Linux-Kernel)