events - What does this line of C# code actually do? -


i'm trying understand block of code in application i've come across bit of c# don't understand.

in code below, code after "controller.progress +=" line do?

i've not seen syntax before , don't know constructs called, can't google find out syntax means or does. instance, values s , p? placeholders?

private void backgroundworker_dowork(object sender, doworkeventargs e) {     using (var controller = new applicationdevicecontroller(e.argument simpledevicemodel))     {         controller.progress +=             (s, p) => { (sender backgroundworker).reportprogress(p.percent); };         string html = controller.getandconvertlog();         e.result = html;     } } 

it looks it's attaching function event, don't understand syntax (or s , p are) , there's no useful intellsense on code.

it's lambda expression being assigned event handler.

s , p variables passed function. you're defining nameless function, receives 2 parameters. because c# knows controller.progress event expects method handler 2 parameters of types int , object, automatically assumes 2 variables of types.

you have defined

controller.progress += (int s, object p)=> { ... } 

it's same if had method definition instead:

controller.progress += doreportprogress; .... public void doreportprogress(int percentage, object obj) { .... } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -