Click here to Skip to main content
15,896,278 members
Home / Discussions / C#
   

C#

 
Questionhelp needed... Pin
arjunsasikumar8-Nov-06 7:48
arjunsasikumar8-Nov-06 7:48 
Questionadd a calculated record Pin
merac#8-Nov-06 7:32
merac#8-Nov-06 7:32 
QuestionC# Anonymous Methods Pin
Jamie Nordmeyer8-Nov-06 5:54
Jamie Nordmeyer8-Nov-06 5:54 
AnswerRe: C# Anonymous Methods Pin
Judah Gabriel Himango8-Nov-06 6:05
sponsorJudah Gabriel Himango8-Nov-06 6:05 
GeneralRe: C# Anonymous Methods Pin
Jamie Nordmeyer8-Nov-06 9:25
Jamie Nordmeyer8-Nov-06 9:25 
GeneralRe: C# Anonymous Methods Pin
Judah Gabriel Himango8-Nov-06 12:40
sponsorJudah Gabriel Himango8-Nov-06 12:40 
GeneralRe: C# Anonymous Methods Pin
Jamie Nordmeyer8-Nov-06 12:53
Jamie Nordmeyer8-Nov-06 12:53 
GeneralRe: C# Anonymous Methods Pin
Judah Gabriel Himango8-Nov-06 13:11
sponsorJudah Gabriel Himango8-Nov-06 13:11 
It's nothing too spectacular; just delegates sitting in some namespace, available to the rest of your code. Thus, your code doesn't have to define custom delegates all over the place; instead, just use a generic one. Here's my (names changed to protect the innocent) file containing several generic delegates[^].

With that file handy, whenever you've got a piece of code that requires a new delegate, instead of defining a new delegate, I just use an existing generic one. Say I need a delegate that returns void and takes 2 strings:

Function<string, string> myFunc = SomeFuncThatTakesTwoStrings;

...

void SomeFuncThatTakesTwoStrings(string first, string second) { ... }


As you can see, no custom delegate declaration required. Easier and more consistent than defining a new delegate each and every time you want to treat a function as a variable. The GenericDelegates file contains definitions for

Function()
Function(T param);
Function(T1 first, T2 second);
...
and so on, all the way up to 6 parameters. I haven't had the need for any more than that, but it's easy to add overloads for more parameters.

I also have ReturnFunction definitions for functions that return something other than void, including the 6 overloads for varying number of parameters.

Again, it isn't anything special; it just removes the burden of having to write custom delegates all over the place. It also allows one's code to be a little more uniform, using the same delegates everywhere rather than class-specific ones.



Tech, life, family, faith: Give me a visit.
I'm currently blogging about: God-as-Judge, God-as-Forgiver
The apostle Paul, modernly speaking: Epistles of Paul

Judah Himango


GeneralRe: C# Anonymous Methods Pin
Jamie Nordmeyer8-Nov-06 13:29
Jamie Nordmeyer8-Nov-06 13:29 
QuestionWMI and restricted user rights Pin
mav.northwind8-Nov-06 5:46
mav.northwind8-Nov-06 5:46 
Questionlock() and return statements: Pin
tomerico8-Nov-06 5:34
tomerico8-Nov-06 5:34 
AnswerRe: lock() and return statements: Pin
Andrew Rissing8-Nov-06 10:56
Andrew Rissing8-Nov-06 10:56 
GeneralThreadSafety Pin
tomerico8-Nov-06 19:05
tomerico8-Nov-06 19:05 
GeneralRe: ThreadSafety Pin
Andrew Rissing9-Nov-06 3:31
Andrew Rissing9-Nov-06 3:31 
Questionpublish my project Pin
daniel998-Nov-06 5:24
daniel998-Nov-06 5:24 
AnswerRe: publish my project Pin
ejuanpp8-Nov-06 5:50
ejuanpp8-Nov-06 5:50 
QuestionWindows-Application terminates abnormally Pin
Daniel_at_Scania8-Nov-06 5:19
Daniel_at_Scania8-Nov-06 5:19 
AnswerRe: Windows-Application terminates abnormally Pin
ejuanpp8-Nov-06 5:27
ejuanpp8-Nov-06 5:27 
GeneralRe: Windows-Application terminates abnormally Pin
Daniel_at_Scania10-Nov-06 1:30
Daniel_at_Scania10-Nov-06 1:30 
GeneralRe: Windows-Application terminates abnormally Pin
ejuanpp10-Nov-06 3:38
ejuanpp10-Nov-06 3:38 
QuestionCall back method for threads Pin
pranu_138-Nov-06 5:18
pranu_138-Nov-06 5:18 
AnswerRe: Call back method for threads Pin
Robert Rohde8-Nov-06 6:22
Robert Rohde8-Nov-06 6:22 
AnswerRe: Call back method for threads Pin
Eric Dahlvang8-Nov-06 8:15
Eric Dahlvang8-Nov-06 8:15 
GeneralNot sure how it fits BUT Pin
Just me at will_george...something8-Nov-06 4:25
Just me at will_george...something8-Nov-06 4:25 
GeneralRe: Not sure how it fits BUT Pin
Pete O'Hanlon9-Nov-06 4:20
mvePete O'Hanlon9-Nov-06 4:20 

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.