为什么委托的减法（- 或 -=）可能出现非预期的结果？（Delegate Subtraction Has Unpredictable R...

▲ 委托的减法可能出现非预期的结果

ReSharper 的官方帮助文档

static void Main()
{
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
}

ReSharper 同时还给出另一个例子，说明委托的减法顺序也可能非预期：

s = a + b + a;
(s - a)();// AB

▲ 调用列表的加减其实就是序列的拼接和子序列的移除

private static event Action s;
static void Main()
{
Action a = () => Console.Write("A");
Action b = () => Console.Write("B");
Action c = () => Console.Write("C");
// 这一句注释掉，因为 s 换成了事件，而事件必须定义在类中。
// 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
}

Code Inspection: Delegate subtractions - Help - ReSharper
events - “Delegate subtraction has unpredictable result” in ReSharper/C#? - Stack Overflow