Properties

Christopher Wright dhasenan at gmail.com
Sun Jan 11 06:23:48 PST 2009


Denis Koroskin wrote:
> On Thu, 08 Jan 2009 03:45:08 +0300, Vishaal <vishaal at nospam.com> wrote:
> 
>> Properties, such as array.length, should return lvalues to allow:
>> a.length += 8;
>> or other similar statements.
> 
> I'd like to point out another related issue that everyone seems to miss.
<snip struct example>

C# also has that flaw. I ran into it a couple of times at work, and as a 
result, we have some types that could easily be POD structs but are 
classes instead.

On the other hand, gmcs (the Mono compiler) errors out when you try 
modifying a struct that you access by a property, and the Microsoft 
compiler probably does as well:
struct_prop.cs(24,21): error CS1612: Cannot modify a value type return 
value of `Foo.bar'. Consider storing the value in a temporary variable
struct_prop.cs(3,8): (Location of the symbol related to previous error)
struct_prop.cs(24,21): error CS0200: Property or indexer `Foo.bar' 
cannot be assigned to (it is read only)
Compilation failed: 2 error(s), 0 warnings



More information about the Digitalmars-d mailing list