C# assign behavior

     double h = Height = newSize.Height;

Height is a property with set and get functions in C#, so what I expected was that set Height was called first – which it does and then that get Height was called secondly – which it does not.

In fact the assign operation will execute the following:

    double h;

    Height = newSize.Height;

    h = newSize.Height;

What I need is this;

   double h;

   Height = newSize.Height;

   h = Height;

The difference is that I coded height limitations into the set function and was not aware that this cascade statement skipped get.

Leave a Reply