tagged [closures]

C# - closures over class fields inside an initializer?

C# - closures over class fields inside an initializer? Consider the following code: ``` using System; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { ...

Closure allocations in C#

Closure allocations in C# I've installed the Clr Heap Allocation Analyzer extension and in a project I see something that I quite don't understand, I've got a method with a signature ``` public Task E...

4 Mar at 10:18

Local variables with Delegates

Local variables with Delegates This appears like it wouldn't be a best practice. Can someone explain why it would not be a best practice or how this works? Any books or articles providing an explanati...

13 Jun at 11:55

Closures in C# event handler delegates?

Closures in C# event handler delegates? I am coming from a functional-programming background at the moment, so forgive me if I do not understand closures in C#. I have the following code to dynamicall...

What is a practical use for a closure in JavaScript?

What is a practical use for a closure in JavaScript? I'm [trying](http://jsbin.com/ojuxo/edit) my hardest to wrap my head around JavaScript closures. I get that by returning an inner function, it will...

22 Jul at 17:33

odd lambda behavior

odd lambda behavior I stumbled across [this article](http://www.float4x4.net/index.php/2011/05/loops-and-lambdas) and found it very interesting, so I ran some tests on my own: Outputs: --- ``

14 Nov at 02:39

Captured Closure (Loop Variable) in C# 5.0

Captured Closure (Loop Variable) in C# 5.0 This works fine (means as expected) in C# 5.0: Prints 0 to 9. But this one shows 10 for 10 times: ``` var actions = new List(); for (var i = 0; i

28 Apr at 15:18

How can I capture the value of an outer variable inside a lambda expression?

How can I capture the value of an outer variable inside a lambda expression? I just encountered the following behavior: Will result in a series of "Error: x", where most of the x are equal to 50. Simi...

Making variables captured by a closure volatile

Making variables captured by a closure volatile How do variables captured by a closure interact with different threads? In the following example code I would want to declare totalEvents as volatile, b...

23 Feb at 13:28

How should I call 3 functions in order to execute them one after the other?

How should I call 3 functions in order to execute them one after the other? If I need call this functions one after other, I know in jQuery I could do something like: ``` $('#art1').animate({'width':'...

How do closures work behind the scenes? (C#)

How do closures work behind the scenes? (C#) I feel I have a pretty decent understanding of closures, how to use them, and when they can be useful. But what I don't understand is how they actually wor...

18 Dec at 14:47

Closures and Lambda in C#

Closures and Lambda in C# I get the basic principles of closures and lambda expressions but I'm trying to wrap my mind around what is happening behind the scenes and when it is/isn't practical to use ...

20 Aug at 15:24

What is so special about closures?

What is so special about closures? I've been [reading this article about closures](http://www.devsource.com/c/a/Languages/Cigars-Lambda-Expressions-and-NET/1/) in which they say: - - - - So I made an ...

17 Apr at 12:4

groovy: safely find a key in a map and return its value

groovy: safely find a key in a map and return its value I want to find a specific key in a given map. If the key is found, I then want to get the value of that key from the map. This is what I managed...

2 Sep at 02:43

Exception: Serialization of 'Closure' is not allowed

Exception: Serialization of 'Closure' is not allowed So I am not sure exactly what I would have to show you guys, how ever if you need more code please do not hesitate to ask: So this method will set ...

5 Dec at 23:12

perl closures and $_

perl closures and $_ One of the first things I try to learn in an unfamiliar programming language is how it handles closures. Their semantics are often intertwined with how the language handles scopes...

5 Jul at 19:10

Access to disposed closure - mark methods as safe

Access to disposed closure - mark methods as safe This is about ReSharper's warning "Access to disposed closure" which usually appears when an object which is later disposed is used in a lambda. [Acce...

Anonymous inner classes in C#

Anonymous inner classes in C# I'm in the process of writing a C# Wicket implementation in order to deepen my understanding of C# and Wicket. One of the issues we're running into is that Wicket makes h...

Issue with closure variable capture in c# expression

Issue with closure variable capture in c# expression I have a function which creates a delegate using expression trees. Within this expression I use a variable captured from multiple parameters passed...

29 Jan at 14:34

using yield in C# like I would in Ruby

using yield in C# like I would in Ruby Besides just using `yield` for iterators in Ruby, I also use it to pass control briefly back to the caller before resuming control in the called method. What I w...

21 Apr at 12:28

Why Are Some Closures 'Friendlier' Than Others?

Why Are Some Closures 'Friendlier' Than Others? Let me apologize in advance - I'm probably butchering the terminology. I have a vague understanding of what a closure is, but can't explain the behaviou...

7 May at 20:25

Closure semantics for foreach over arrays of pointer types

Closure semantics for foreach over arrays of pointer types In C# 5, the closure semantics of the `foreach` statement (when the iteration variable is "captured" or "closed over" by anonymous functions)...

23 May at 11:44

Getting ConstantExpression.Value when actual value wrapped into DisplayClass because of closure

Getting ConstantExpression.Value when actual value wrapped into DisplayClass because of closure Below is a simple demonstration code of my problem. ``` [TestClass] public class ExpressionTests { [Te...

Is there a particular reason LinqKit's expander can't pick up Expressions from fields?

Is there a particular reason LinqKit's expander can't pick up Expressions from fields? I'm using [LinqKit](http://www.albahari.com/nutshell/linqkit.aspx) library which allows combining expressions on ...

Is this object-lifetime-extending-closure a C# compiler bug?

Is this object-lifetime-extending-closure a C# compiler bug? I was answering a [question](https://stackoverflow.com/questions/8417470/private-field-captured-in-anonymous-delegate) about the possibilit...