tags:

views:

130

answers:

2
class Bar
{
  private byte[] dg;

  Bar(byte[] datagram)
  {
    dg = datagram;
  }

  int Foo
  {
    get { return BitConverter.ToInt16(dg, 8); }
  }
}

When are properties evaluated? At the time Foo is accessed? The debugger evaluating all properties is scaring me.

+7  A: 

Yes, a property is just syntactic sugar for the call to get accessor method. Every time property is read, the method executes. And yes, this does include the debugger (which is why if your property gettors have side effects, debugging can actually affect the way your program works).

Pavel Minaev
+1  A: 

Yes, C# properties are simply syntactic sugar for specialized methods so they are evaluated when called, like any other type of instance method.

Lee