开发者

listener c# like java

开发者 https://www.devze.com 2022-12-20 08:41 出处:网络
I have field string in struct, and i want learn real-time changed this field. struct example { public string ex;

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);
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号