C
C#3y ago
Xan.Nava

Combining func reference behavior [Answered]

If i combine func3 += func1 and func3 += func2 and then lets say func1 += someMethod Will func3 also have it added?
10 Replies
mtreit
mtreit3y ago
Well, not directly But indirectly yes Like if you removed func1 from the chain subsequently then invoking func3 will not result in a call to someMethod
Xan.Nava
Xan.NavaOP3y ago
Exactly what I was hoping for Though if you did func3 -= someMethod would it be removed from func1 also?
333fred
333fred3y ago
No
Xan.Nava
Xan.NavaOP3y ago
Is it is more like sets. The func3 set has two sets in it func1 and func2, and then func1 is a set with someMethod in it? So removing someMethod from func3 wouldn't work because it's set is just func1 and func2 but calling func3 will call everything in its sub sets?
MODiX
MODiX3y ago
Orannis#3333
REPL Result: Success
var func1 = () => Console.WriteLine("Func1");
var func2 = () => Console.WriteLine("Func2");
var func3 = () => Console.WriteLine("Func3");
var combined1and2 = func1 + func2;
var combinedAll3 = func3 + combined1and2;
combined1and2 -= func2;
combinedAll3();
var func1 = () => Console.WriteLine("Func1");
var func2 = () => Console.WriteLine("Func2");
var func3 = () => Console.WriteLine("Func3");
var combined1and2 = func1 + func2;
var combinedAll3 = func3 + combined1and2;
combined1and2 -= func2;
combinedAll3();
Console Output
Func3
Func1
Func2
Func3
Func1
Func2
Compile: 629.132ms | Execution: 69.840ms | React with ❌ to remove this embed.
mtreit
mtreit3y ago
Yes, think of it as a graph
333fred
333fred3y ago
See how modifying combined1and2 didn't affect combinedAll3?
Xan.Nava
Xan.NavaOP3y ago
ah yeah
333fred
333fred3y ago
I'm going to assume this is done
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server