Are there any good reasons why closures aren't immutable in C#? -


I am going to my head on this, and I do not seem to come up with a good reason why C # is unstable It seems that there is a good way to get some unexpected results, if you do not know what's really going on.

Perhaps someone else who may be a bit knowledgeable, can be highlighted that to change the state of C # in a conclusion?

Example:

  var foo = "hello"; Action Bar = () = & gt; Console.WriteLine (foo); times (); Foo = "Bye"; times ();  

This will print "Hello" for the first call, but for the second call in the external call, "Goodbye" is printed. The closing position was updated to reflect the local variables changes.

C # and Javascript, as well as O'Caml and Haskell, and many other languages It is known as Laxic Closer This means that the internal function, values ​​ copy not only the attached functions name of the local variable In languages ​​with irreversible symbols, closing names like Okamal or Haskell can be similar to closing prices, so both The difference between type of closing disappears; Despite these languages ​​there are also lexical closures like C # and Javascript.


Comments