Nick Sabalausky wrote:
"Chad J" <chadj...@__spam.is.bad__gmail.com> wrote in message
news:h4oku0$ue...@digitalmars.com...
Daniel Keep wrote:
Maybe the compiler could rewrite the above as:
auto t = a.b;
t.c = 3;
a.b = t;
I'd always suspected C# properties did something like this, though it's
been so long since I've used C# now that I'm wondering if it's bad memory.
Same here, so I just did a little test in Visual C# 2008 Express. Turns out
that rewriting *is* exactly what C# does.
Code:
--------------------------------------
using System;
namespace ConsoleApplication1
{
class Program
{
class Rect
{
public int width;
public int height;
public Rect(int width, int height)
{
this.width = width;
this.height = height;
}
}
class Widget
{
public Rect size { get; set; }
public Widget()
{
size = new Rect(50,50);
}
}
static void Main(string[] args)
{
Widget wid = new Widget();
Console.Out.WriteLine("width: "+wid.size.width);
Console.Out.WriteLine("height: "+wid.size.height);
wid.size.width = 100;
Console.Out.WriteLine("width: "+wid.size.width);
Console.Out.WriteLine("height: "+wid.size.height);
Console.ReadLine(); // So I can *read* the dang output
}
}
}
--------------------------------------
Compiles successfully.
Output:
--------------------------------------
width: 50
height: 50
width: 100
height: 50
--------------------------------------
As far as I understand, this example is not relevant because there are
no structs involved.
Andrei