委托解绑的一个小问题

在对委托使用-=解绑方法时,resharper会出现一个提示:Delegate substraction has unpredictable result。

http://confluence.jetbrains.com/display/ReSharper/Delegate+subtraction+has+unpredictable+semantics 解释了原因。

根据该网页所举出的示例:

                Action a = () => Console.Write("A");
                Action b = () => Console.Write("B");
                Action c = () => Console.Write("C");
                Action s = a + b + c + Console.WriteLine;
                s();                  //ABC
                (s - a)();            //BC 
                (s - b)();            //AC  
                (s - c)();            //AB   
                (s - (a + b))();      //C 
                (s - (b + c))();      //A  
                (s - (a + c))();      //ABC 
                Console.Read();

(s - (a + c))(); 
a+c并不是一个ABC委托连的子集,因此,该行代码无效,仍然会执行所有委托连上的方法。
原文地址:https://www.cnblogs.com/Benjamin/p/3350371.html