Properties in C# and prop_Foo

grauzone none at example.net
Sun Aug 9 11:25:49 PDT 2009


Bill Baxter wrote:
> Interesting thing I found out about C# properties.
> The syntax
> 
> int Thing {
>    get { return _thing; }
>    set { _thing = value; }
> }
> 
> is rewritten by the C# compiler into
> 
> int prop_Thing() { return _thing; }
> void prop_Thing(int value) { _thing = value; }
> 
> Just thought it was interesting given all our discussions,
> particularly that the syntax C# translates into is exactly what Andrei
> was proposing we use for D's syntax.  And I think I even said that was
> fine, but let's have a different syntax for declaring that the D
> compiler translates into those prop_Thing methods.  Well, it turns out
> that's exactly what C# does.

C# doesn't allow you to directly call the accessors (which are named 
set_Thing and get_Thing, btw.). It also creates and associates metadata 
with the property (so that you know that "Thing" is supposed to be a 
property with these setters and getters).

In C# (as in the language) properties still work as cast into concrete; 
it's just that on the lowest level, it is mapped to normal methods + 
extra metadata.

That's probably not quite what was proposed.

> --bb



More information about the Digitalmars-d mailing list