C# envy: properties
Recently I found out that in c#, if you want to put a variable behind a public getter and private setter, so that it can be read but not changed, you can do it on one line! Here it is:
public int x { get; private set; }
Or if you want both public, it would be:public int x { get; set; }
In ActionScript3 this would be:
The c# way is so much nicer - feature request Adobe!
private var _x:int;
public function get x():int
{
return _x;
}
public function set x(_x:int):void
{
this._x = _x;
}
Comments
Did you know you could convert c# to actionscript? :P
Yeah but you can have no setter at all, which pretty much achieves the same thing - a read-only property.
"Did you know you could convert c# to actionscript? :P"
- what automagically? how? (what happens to enums etc?)
@property int x;
@synthesize x;
http://labs.adobe.com/wiki/index.php/Alchemy