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

C#

 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff5-May-13 0:28
mveOriginalGriff5-May-13 0:28 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kevin Bewley29-Apr-13 0:30
Kevin Bewley29-Apr-13 0:30 
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 
It's just like the compiler told you... you can only "point" to a lambda via a delegate type. Dems da rules. Sorry.


BillWoodruff wrote:
private void MethodTakesAFunc(Func<dynamic, dynamic, string> theFuncParam)
{
string evalFunc = theFuncParam.DynamicInvoke();
}


I don't get it... this works just fine:

C#
private void MethodTakesAFunc(Func<dynamic, dynamic, string> theFuncParam)
{
    //string evalFunc = theFuncParam.DynamicInvoke();
    string s = theFuncParam(someRandomVar1, someRandomVar2);
}


As for the uses of a lambda... well, some people "var them all up". What I mean by that is, I've seen a lot of C# code where people go hog wild with var...

var x = 0;
var y = new List<int>();

etc. Not what a var is intended for at ALL. I've seen people similarly write several page long functions in an inline lamda just cuz they are too lazy too create a function. Style wise, I think if your lambda code is < 5 lines or so, its fine to put it inline, but anything more then that it should be a separate function.

One trick you can do with lambdas is to change a methods signature. Typical UI event handlers are object sender, EventArgs e. Lets say you don't find any of those params useful, and you instead want to pass in a structure. That would require making that structure a class variable so the event handler can access it, but instead you can do:

button.Clicked += (x, y) => { MyEventHandler(someLocalObject); }
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 
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 

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.