As the title says. Where do they go? they're variables, but they're also code...
+1
A:
They should go where they're needed. Can you clarify your question?
A variable that holds a reference to a lambda (or any Delegate) is still a variable. Treat it like a variable.
That doesn't mean you HAVE to use variables. You can just specify the lambda inline in many cases.
John Weldon
2009-06-10 05:43:40
what is unclear?
RCIX
2009-06-10 05:45:57
do you mean where should I declare the variables that hold the reference to the lambda? if so: with the variables.
John Weldon
2009-06-10 05:50:02
See my example.
RCIX
2009-06-10 05:53:02
A:
I'd put them with the rest of your variables, since they can be reassigned and changed just like any other variable. Like this:
class Test
{
string s = "abcdefg";
int one = 1;
Func<int> myFunc;
void MyMethod()
{
int x = 5;
float f = 3.86;
Action<string> a;
}
}
I'm not quite sure what else (or where else) you would mean?
jasonh
2009-06-10 05:44:38
I think this is personal taste really. If you plan to reassign them, you may want to put them with variables. On the other hand, it may be cleaner to put them with the rest of your code, especially if you use region tags to group your code.
jasonh
2009-06-10 05:52:23