Click here to Skip to main content
15,887,322 members
Home / Discussions / C#
   

C#

 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot29-Apr-13 0:38
harold aptroot29-Apr-13 0:38 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kevin Bewley29-Apr-13 0:40
Kevin Bewley29-Apr-13 0:40 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot29-Apr-13 0:43
harold aptroot29-Apr-13 0:43 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv5-May-13 0:29
N8tiv5-May-13 0:29 
Questionwhy you can't store a lambda expression in a 'dynamic variable, or 'var variable ? Pin
BillWoodruff27-Apr-13 18:33
professionalBillWoodruff27-Apr-13 18:33 
AnswerRe: why you can't store a lambda expression in a 'dynamic variable, or 'var variable ? Pin
SledgeHammer0127-Apr-13 18:54
SledgeHammer0127-Apr-13 18:54 
GeneralRe: why you can't store a lambda expression in a 'dynamic variable, or 'var variable ? Pin
BillWoodruff27-Apr-13 19:41
professionalBillWoodruff27-Apr-13 19:41 
GeneralRe: why you can't store a lambda expression in a 'dynamic variable, or 'var variable ? Pin
SledgeHammer0127-Apr-13 20:07
SledgeHammer0127-Apr-13 20:07 
I'm not sure what you are getting at with passing in nulls to execute the lamdba. If you have two dynamics as parameters to the function, that means you can pass anything into them, but you should pass something.

What I was demonstrating with changing the signature of a function is:

private void SomeMethod()
{
// random code here
// some more random code here
SomeComplexObject o = ...; // SomeComplexObject is built from the above random code
theButton.Click += MyEventHandler;
}

Ok, so without lamdas, how do you get "o" to MyEventHandler? You'd have to make it a class member, right? Seems lame to store a local object as a class member just for the sake of passing it to an event handler.

private void SomeMethod()
{
// random code here
// some more random code here
SomeComplexObject o = ...; // SomeComplexObject is built from the above random code
theButton.Click += (x, y) => { MyCoolerEventHandler(o); }
}

No, I didn't really "change the sig of the method" per say if you want to nitpick, but I passed o to my event handler in what I think is a much cleaner way then making it a class member.

One use of that is lets say you have a static object for whatever reason that has an event that takes an x & y. Without lamdas, you have no way to pass additional stuff into that function.

class MyClass
{
private static SomeClassWithEvents;

MyClass()
{
SomeClassWithEvents.theEvent += theHandler;
}

static void theHandler(x, y)
{
}

}

what if I want the handler to have access to SomeClassWithEvents... I'd either have to add a static "this" pointer:

static MyClass classPtr;

and init that.. or I could just do:

SomeClassWithEvents.theEvent += (x, y) => { theHandler(x, y, this); }

modified 28-Apr-13 2:13am.

AnswerRe: why you can't store a lambda expression in a 'dynamic variable, or 'var variable ? Pin
Richard Deeming29-Apr-13 2:19
mveRichard Deeming29-Apr-13 2:19 
GeneralRe: why you can't store a lambda expression in a 'dynamic variable, or 'var variable ? Pin
BillWoodruff29-Apr-13 14:07
professionalBillWoodruff29-Apr-13 14:07 
QuestionExtract Date part and pass only Date Pin
meeram3927-Apr-13 4:24
professionalmeeram3927-Apr-13 4:24 
AnswerRe: Extract Date part and pass only Date Pin
Dave Kreskowiak27-Apr-13 5:31
mveDave Kreskowiak27-Apr-13 5:31 
AnswerRe: Extract Date part and pass only Date Pin
jschell27-Apr-13 11:15
jschell27-Apr-13 11:15 
GeneralJogar uma imagem em um picturibox, apartir de um clique em uma linha do datagridview Pin
Member 1000184526-Apr-13 13:15
Member 1000184526-Apr-13 13:15 
GeneralRe: Jogar uma imagem em um picturibox, apartir de um clique em uma linha do datagridview Pin
dusty_dex26-Apr-13 13:36
dusty_dex26-Apr-13 13:36 
GeneralRe: Jogar uma imagem em um picturibox, apartir de um clique em uma linha do datagridview Pin
Member 1000184526-Apr-13 15:30
Member 1000184526-Apr-13 15:30 
GeneralRe: Jogar uma imagem em um picturibox, apartir de um clique em uma linha do datagridview Pin
Dave Kreskowiak26-Apr-13 17:16
mveDave Kreskowiak26-Apr-13 17:16 
GeneralRe: Jogar uma imagem em um picturibox, apartir de um clique em uma linha do datagridview Pin
Member 1000184526-Apr-13 23:54
Member 1000184526-Apr-13 23:54 
GeneralRe: Jogar uma imagem em um picturibox, apartir de um clique em uma linha do datagridview Pin
Dave Kreskowiak27-Apr-13 4:09
mveDave Kreskowiak27-Apr-13 4:09 
GeneralRe: Jogar uma imagem em um picturibox, apartir de um clique em uma linha do datagridview Pin
Richard MacCutchan26-Apr-13 22:25
mveRichard MacCutchan26-Apr-13 22:25 
GeneralRe: Jogar uma imagem em um picturibox, apartir de um clique em uma linha do datagridview Pin
Member 1000184526-Apr-13 23:45
Member 1000184526-Apr-13 23:45 
QuestionData in XmlFiles or in Database Pin
Frygreen26-Apr-13 7:42
Frygreen26-Apr-13 7:42 
AnswerRe: Data in XmlFiles or in Database Pin
Dave Kreskowiak26-Apr-13 7:52
mveDave Kreskowiak26-Apr-13 7:52 
GeneralRe: Data in XmlFiles or in Database Pin
Frygreen26-Apr-13 8:08
Frygreen26-Apr-13 8:08 
GeneralRe: Data in XmlFiles or in Database Pin
Dave Kreskowiak26-Apr-13 8:22
mveDave Kreskowiak26-Apr-13 8:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.