I have field string in struct, and i want learn real-time changed this field.
struct example {
public string ex;
}
examp = new example();<BR>
examp.ex = "te开发者_Python百科st";
////// then program work and eamp.ex = "bing";
I need method
on_ex_changed()
{
if examp.ex changed then .....
}
online and simple plz
You can put an event at the setter as follows. The event will be fired every time the setter is called.
public class MyObj
{
private RectangleF mRectangle;
public event EventHandler RectangleChanged;
public RectangleF Rectangle
{
get
{
return mRectangle;
}
set
{
mRectangle = value;
OnRectangleChanged();
}
}
protected virtual void OnRectangleChanged()
{
if (RectangleChanged != null)
{
RectangleChanged(this, EventArgs.Empty);
}
}
}
精彩评论