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
0
votes
1 answer

Passing Action as anonumous method or lambda expression

I have a method with this signature, void Add(Control control, Action redraw) I need to call it like this myClass.Add(myControl, {Some code}); Where {Some Code} to be replaced with anonymous function. P.S. Action redraw doesnt take or return any…
Sisyphus
  • 900
  • 12
  • 32
0
votes
2 answers

Anonymous methods and Async I/O

Can anyone tell me if I'm likely to run into unintended behavior if I use anonymous methods with Async I/O? As an example: Action acceptedHandler = DoAccept SocketAsyncEventArgs e = new SocketAsyncEventArgs(); e.Completed += ((sender, ea)…
Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
0
votes
1 answer

Scope and anonymous methods

I have this rather simple logic: class Program { static void Main(string[] args) { using (TransactionScope ts = new TransactionScope()) { System.Threading.Tasks.Parallel.Invoke(() => { …
Pete
  • 6,585
  • 5
  • 43
  • 69
0
votes
2 answers

How to create a local web server anonymously?

I have a local web server using Apache2 and people can access it just having my external IP address. What I wanna do is to use some IP else so that way I will need to pass the false IP to my visitor and he will connect to my web server through that…
Bole Grat
  • 71
  • 10
0
votes
1 answer

Recompiling the OpenXmlSdkTool.Core DLL with a anon-method and delegate error

I'm doing research into the OpenXmlSdkTools v2.5 and had a sneak peak inside the OpenXmlSdkTools.Core.DLL and saved it as a c# Project with ILSpy. While this question is active, here is the OpenXmlSdkTools.Core.DLL as a way to quickly reproduce the…
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
0
votes
1 answer

Why the chain of functions does not work in PHP?

I was writing code for YIi, fileuploading. When I write this: $model->album_photocover = CUploadedFile::getInstance($model, 'album_photocover'); $model->album_photocover->saveAs($path . '/' . $model->album_photocover); it works. …
khunshan
  • 2,662
  • 4
  • 28
  • 34
0
votes
1 answer

Anonymous Method in Object initializer

I am creating a quiz in which have following class Quiz with properties CorrectOption, WrongOption1, WrongOption2, WrongOption3. in its DTO i have the List Options that will contain all wrong and correct options. While retrieving the…
LojiSmith
  • 282
  • 3
  • 20
0
votes
3 answers

PHP Import Foreign Class' Method into MyClass

Wondering if this is possible in PHP Land: Let's say I have a class as follows: class myClass{ var $myVar; ... myMethod(){ $this->myVar = 10; } } and another class: class anotherClass { ... addFive(){ $this->myVar +=…
safoo
  • 528
  • 1
  • 4
  • 15
0
votes
3 answers

Adding Controls to asp Table Anonymously

I want to do the following functionalities anonymously. How should I do this - TableRow tr = new TableRow(); TableCell tc = new TableCell(); Label lbl = new Label(); lbl.Text = link; …
RTRokzzz
  • 235
  • 1
  • 4
  • 14
0
votes
3 answers

JavaScript-like anonymous functions in C#

Can the following be done in C#?: var greeting = "Hello" + function () { return " World"; }() + "!"; I want to do something along the lines of this (C# pseudo code): var cell = new TableCell { CssClass = "", Text = return delegate () { …
cllpse
  • 21,396
  • 37
  • 131
  • 170
0
votes
1 answer

Annoumous Function In VB.net

I have the following line of code in c#. Check.ThatIsNotAnEmptyString(line1, () => { throw new InvalidAddressException("An address must have a street"); }); I am having difficulty converting it to vb.net. I used the conversion tool…
user1180223
  • 111
  • 8
0
votes
1 answer

Simple Anonymous Method in C#

See the second bit of code below.. code doesn't compile. Am trying to figure out anon methods, and I get it.. But not the example of not using anon methods which I found on the web, which doesn't compile Using VS2008.. compiling to .NET3.5 using…
Dave Mateer
  • 6,588
  • 15
  • 76
  • 125
0
votes
1 answer

Need help debugging an unknown anonymous method runtime error in flash

I am running a large flash application that makes heavy use of anonymous methods for events. I have an anonymous method that has a type 1010 error, that is caught by my uncaught exception handler. This error is encountered by users, I have never…
marcus
  • 1
0
votes
2 answers

How can I resume setInterval after clearInterval has been called in javascript?

I have this code which works ok but I would like to stop polling and clearInterval if the user is inactive (no mouse move) after say 5 iterations rather than be in a continuous loop. var i, active = new Date, iter = 1; $(window).on('mousemove',…
Hcabnettek
  • 12,678
  • 38
  • 124
  • 190
-1
votes
1 answer

How and where are anonymous methods without parameters used?

When comparing anonymous methods to lambda expressions, I've seen explanations that anonymous methods provide flexibility. Flexibility here means that you can omit parameters from anonymous methods. // inflexible anonymous method Action action…
isakgo_
  • 750
  • 4
  • 15
1 2 3
21
22