有一个static的字符串,我想让其值在改变的时候触发一个windows事件,去执行一系列的方法,请问该怎么弄呢?提供点简短代码或者思路皆可,谢谢各位了。

解决方案 »

  1.   

    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";
      

  2.   

    少个)括弧。 MessageBox.Show(string.Format("{0} changed to {1}", originalValue, currentValue));