c# - Delegates are immutable but how? -


what happens when add method existing delegate? mean when added method1 del, del holds address of method1. when add method2 afterwards, del still points method1 , method 2 address inserted on bottom of it. doesn't mean changed delegate? if can change why in books told "delegates immutable" ?

mydel del = method1;  del += method2;  del += method3; 

let me use simple analogy. int immutable, when put

int x = 123; x += 1; 

it means

int _x = x + 1; x = _x; 

when adding 1 new temporary variable _x , drop initial x substituting _x; in case of delegates

del += method2;  

means quite same:

delegate _del = delegate.combine(del, method2); del = (mydel) _del; 

Comments

Popular posts from this blog

sql - can we replace full join with union of left and right join? why not? -

javascript - Parallax scrolling and fixed footer code causing width issues -

iOS: Performance of reloading UIImage(name:...) -