Re: Why properties cannot be used as ref or out arguments
Jon Skeet <[email protected]> Mon, 10 Mar 2008 09:32:08 +0000
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <[email protected]> |
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 =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com