[inline]

On Wed, 29 May 2002 21:51:14 +0100, Ian Griffiths <[EMAIL PROTECTED]>
wrote:

>Arild Fines <[EMAIL PROTECTED]> wrote:
>
>> >FWIW - I think Petzold misunderstood/misrepresented something
>> > there. His example was referring to someControl.Size.Width * 2;
>> > something which will fail because the Size property will return a
>> > copy of the Size struct.
>> >
>> > Making changes to the Width property of the returned struct will
>> > have no effect onthe original and the whole statement is pointless.
>> > The compiler recognizes this and issues a warning(or an error -
>> > dont remember offhand).
>
>From: "Jon Jagger" <[EMAIL PROTECTED]>
>
>> But the whole statement might _not_ be pointless. One of the
>> main points of a property is that a write context you don't get
>> an assignment you get a set accessor.
>
>Ah, but this isn't a write context.

It was in my original question.

>At least it's not for the Size
>property.  This causes a *get* of the Size.  It might then perform a set
on
>the size struct's Width, but it'll be a copy of the Size that it performs
>the set on.  And unless the Size were to hold a reference back to its
>containing object (which would pretty much defeat the purpose of making
it a
>value type in the first place) then there's nothing useful that the
>Size.Width set accessor can do anyway.

That's a bold statement. I myself don't claim to be omnipotent ;-) I can
just about image a scenario where it might be useful.
Consider a _class_ that contains a property which is not trivial. Suppose
the property contains two sub properties that have a mutual constraint
(something similar cropped in a posting recently). In this case you might
want to provide a top level property _and_ a nested property. In this case
making the top level property return a struct containing a reference back
to the object might be a useful optimization.

Bt be that as it may, my question is still is there a _fundamental_ reason
that only compiler writers currently know about (as implied by Petzold).

Cheers
JJ


>
>--
>Ian Griffiths
>DevelopMentor
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to