像Java一样的侦听器C# [英] listener c# like java
本文介绍了像Java一样的侦听器C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在struct中有字段字符串, 而且我想了解实时更改此领域的情况.
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 = "test";
////// then program work and eamp.ex = "bing";
我需要方法
on_ex_changed()
{
if examp.ex changed then .....
}
在线和简单的plz
推荐答案
您可以按照以下步骤在设置器上放置一个事件. 每次调用setter时都会触发该事件.
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);
}
}
}
这篇关于像Java一样的侦听器C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文