C#自定义事件的问题 有一个static的字符串,我想让其值在改变的时候触发一个windows事件,去执行一系列的方法,请问该怎么弄呢?提供点简短代码或者思路皆可,谢谢各位了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class SomeObj{ public static event Action<string, string> OnSomeValueChanged; private static string _someValue; public static string SomeValue { get { return _someValue; } set { if (_someValue != value) { if (OnSomeValueChanged != null) OnSomeValueChanged(_someValue, value); _someValue = value; } } }}// 使用:SomeObj.OnSomeValueChanged += (originalValue, currentValue) => { MessageBox.Show(string.Format("{0} changed to {1}", originalValue, currentValue);};SomeObj.SomeValue = "test"; 少个)括弧。 MessageBox.Show(string.Format("{0} changed to {1}", originalValue, currentValue)); 求助,没用接触过C#,但是工作需要做一个修改,求助!!!! 在自学WCF过程中, 遇到了一个问题,很简单。 windows form: form.show () 问题 C#调用C++的DLL的问题,急啊!! 请教一下类和对象的生命周期问题? 怎么判断一个字符串内是否包含指定的字符串? VS2008设计页面问题 c#udpclient问题 急!!!为什么遍历不到动态添加的控件? 公钥标记两问(三处的不同,及卸载问题) C# 横线不能显示 问一个简单问题, 怎样选中一个指定的 TreeNode
{
public static event Action<string, string> OnSomeValueChanged;
private static string _someValue;
public static string SomeValue
{
get { return _someValue; }
set
{
if (_someValue != value)
{
if (OnSomeValueChanged != null)
OnSomeValueChanged(_someValue, value);
_someValue = value;
}
} }
}// 使用:
SomeObj.OnSomeValueChanged += (originalValue, currentValue) =>
{
MessageBox.Show(string.Format("{0} changed to {1}", originalValue, currentValue);
};SomeObj.SomeValue = "test";