Questions tagged [anonymous-methods]

An anonymous method is a procedure or function that does not have a name associated with it.

An anonymous method is a procedure or function that does not have a name associated with it. An anonymous method treats a block of code as an entity that can be assigned to a variable or used as a parameter to a method. In addition, an anonymous method can refer to variables and bind values to the variables in the context in which the method is defined. They are similar to the construct of closures defined in some languages.

An anonymous method in C# is a way to pass a code block as a delegate parameter.

320 questions
1
vote
1 answer

references kept by anonymous methods and lambdas

are there any differences in the references that are produced in code generated for anonymous methods by a .NET 2.0 or 4.0 compiler and code generated for an equivalent lambda by a .NET 4.0 compiler? and in particular for the this pointer: I know…
mtijn
  • 3,610
  • 2
  • 33
  • 55
1
vote
2 answers

What happens when we use operators in ruby

As i understand when we add two numbers in ruby a '+' method is called on the current object with parameter as the the next object. >> 2 + 3 => 5 >> 2.+(3) => 5 How are these two examples same is it possible that we can call methods on objects…
1
vote
2 answers

PHP create_function Instance variable - Unable to call anonymous function: Follow up

This is somewhat a follow up to a previous question - but I've distilled the question down and have the "works" vs. "doesn't work" cases narrowed down much more precisely. My Goal: I have a class MyClass that has an instance variable myFunction.…
DJSunny
  • 1,970
  • 3
  • 19
  • 27
1
vote
2 answers

javascript classes scope and anonymous functions

I have a javascript class declared as shown below.. My problem is the aonymous function does not see the scope of the class. I can not reference the bb_obj from within the ajax call load callback.. Is there a way to do this? Thanks in advance..…
Lee
  • 5,816
  • 6
  • 45
  • 61
1
vote
2 answers

VB.NET to C#: Using Data-Binding methods on object

In VB.NET I created 2 shorthand functions for data binding gridviews/dropdownlists/etc from any datasource (such as a DataReader or IReader or collection, etc): Public Shared Sub BindObject(ByVal objDataSource As Object, ByVal objItem As Object) …
Peter
  • 161
  • 3
  • 9
1
vote
2 answers

Can we update a list using anonymous methods?

I have a list (MyList) of objects...and I would like to update one property (Priority) of each item in that list. Will the below code work for that ? this.MyList.All( delegate(ItemViewModel itemObject) { itemObject.Priority =…
Relativity
  • 6,690
  • 22
  • 78
  • 128
1
vote
1 answer

CodeDom - can I generate an anonymous method?

I can't find any way to generate an anonymous method. any ideas?
Thomas
1
vote
1 answer

Why is anonymous method that has expression of type int having its type inferred as Func?

I have a generic function that is supposed to traverse a sequence of properties within a LINQ expression to compare against another passed-in value but discovered that the LINQ expression contained a convert operation, which my function was not…
themills22
  • 13
  • 2
1
vote
2 answers

How to add quotes around each list element after .add?

I have a List private List additionalHeaderMeta = new List(); and I want to output it to a csv file. All that is working find but it turns out some of the elements I am adding to additionalHeaderMeta might have commas in them…
Brad
  • 11,934
  • 4
  • 45
  • 73
1
vote
1 answer

Getting the target of an anonymous method

The following methods are part of a base class which enables derived classes to specify who should be notified by an event. protected void RaiseEvent(EventHandler updateEvent, TEventArgs eventArgs, UpdateReceivers…
leozilla
  • 1,296
  • 2
  • 19
  • 29
1
vote
2 answers

Conditional assignment using delegate

I want to assign to a datatable such that. If datatable is null create a new datatable else clear datatable The code I have written datatable= (datatable== null) ? new DataTable() : delegate(){datatable.Clear(); return datatable;}); How…
Zain Ali
  • 15,535
  • 14
  • 95
  • 108
1
vote
1 answer

C# anonymous function log method body

I am working on an application where we need to log entire statement of anonymous (lambda) function. What it means is that the "LogAction" method should log all the statements that are passed as action. protected void LogAction(Action…
user2107373
  • 427
  • 3
  • 16
1
vote
3 answers

Anonymous method return type casting

I have an object "ConnectableProperty" that hooks up one property to another, and requires I feed it Func. Now I have 2 types at the moment - Scalar and Color. Both are castable to each other via explicit operators. For some reason I can't feed a…
George R
  • 3,784
  • 3
  • 34
  • 38
1
vote
1 answer

C# Subscribe dynamically anonymous method

Hello yeah I'm asking this question a second time, sorry about that but I don't know how to bump previous question. I'll explain more in depth my problem in a more completed example. Instead of writing like 300+ Event classes in 300 class files…
SSpoke
  • 5,656
  • 10
  • 72
  • 124
1
vote
3 answers

Replace function call with anonymous method

I feel stupid. Can you guys help me to replace GetCamp(x) with anonymous? This code: aspnet_Users.ForEach(x => { usersVm.Add(new User{ Camp = Mapper.Map(GetCamp(x)), }); });…
iLemming
  • 34,477
  • 60
  • 195
  • 309