Question about C# properties

Posted by Impz0r on Stack Overflow See other posts from Stack Overflow or by Impz0r
Published on 2010-04-22T12:15:48Z Indexed on 2010/04/22 12:23 UTC
Read the original article Hit count: 239

Filed under:

Hey there,

i bumped the other day into a little problem regarding C#'s properties.

Let's say i do have this setup:

public class Point
{
 public float X;
 public float Y;
}

public class Control
{
 protected Point m_Position = new Point();

 public Position
 {
  get { return m_Position; }
  set 
  { 
    m_Position = value; }
    // reorganize internal structure..
    reorganize();
  }

  protected reorganize()
  {
   // do some stuff
  }
}

This is all fine, but when it comes to usage, i could write something like:

Control myControl = new Control();
myControl.Position.X = 1.0f;

The thing is, my Control class wont recognize that the Position has been changed because set hasn't been called.

So i guess my question is, is there a way to make Control aware of any Position changes?

Thanks in advance!

Mfg Imp

© Stack Overflow or respective owner

Related posts about c#