Re: Why properties cannot be used as ref or out arguments
Dean Cleaver <[email protected]> Mon, 10 Mar 2008 22:44:10 +1300
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <4543A775711185429E59B18055D4167423225D@sxslakl004.xceptionsoftware.com> |
Yeah - getting my head around it now. Sadly, it's not VB I wanted it for. Is a shame- looks like I will have to declare 2 variables, pass them in, and then analyse the returned responses to achieve what I want - takes the "ideal" 1 line call to about 7 or 8 at least - was trying to encapsulate a call, but it might not be feasible. Dino -----Original Message----- From: Discussion of development on the .NET platform using any managed language [mailto:[email protected]] On Behalf Of Jon Skeet Sent: Monday, 10 March 2008 22:32 To: [email protected] Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out arguments Dean Cleaver wrote: > I can understand ref arguments, because they might not be set on > passing, but I can't figure out why they can't be used as out arguments? > > Any thoughts? That's not the reason for not being able to use them as ref. When you pass a parameter by out/ref, you're effectively passing an address that the called method can use as the variable address. It can treat it like any other variable in terms of storing and fetching values directly (subject to definite assignment rules for out, of course). Properties don't work like this - they're not slots in memory, to be arbitrarily accessed. Note that if you use properties for out/ref parameters in VB, basically a temporary variable is created, *that* is passed by out/ref, and the property is set appropriately after method has completed. Jon =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D This list is hosted by DevelopMentor=AE http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com