-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelegateRemoveAdvanced.cs
More file actions
40 lines (29 loc) · 970 Bytes
/
Copy pathDelegateRemoveAdvanced.cs
File metadata and controls
40 lines (29 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
public static class Program {
public static void Main (string[] args) {
var ca = new MyClass(1);
var cb = new MyClass(2);
Action ap = ca.PrintSelf, bp = cb.PrintSelf, ap2 = ca.PrintSelf, bp2 = cb.PrintSelf;
CompareDelegates(ap, ap);
CompareDelegates(ap, bp);
CompareDelegates(ap, ap2);
Delegate twiceAp = Delegate.Combine(ap, ap);
Delegate apPair = Delegate.Combine(ap, ap2);
CompareDelegates(twiceAp, apPair);
Delegate onceAp = Delegate.Remove(twiceAp, ap);
CompareDelegates(onceAp, twiceAp);
CompareDelegates(onceAp, ap);
}
public static void CompareDelegates (Delegate a, Delegate b) {
Console.WriteLine(a == b ? "true" : "false");
}
}
public class MyClass {
public int Value;
public MyClass (int value) {
Value = value;
}
public void PrintSelf () {
Console.WriteLine("{0}", Value);
}
}