Click here to Skip to main content
15,867,838 members
Home / Discussions / C#
   

C#

 
AnswerRe: How do you make a .net component run as an embedded resource? Pin
Heath Stewart18-Jan-04 11:15
protectorHeath Stewart18-Jan-04 11:15 
QuestionShould I keep using it or should I change? Pin
caheo17-Jan-04 14:25
caheo17-Jan-04 14:25 
GeneralBUG: Graphics.DrawString Pin
leppie17-Jan-04 11:25
leppie17-Jan-04 11:25 
GeneralWhat do you want to do today? Pin
leppie17-Jan-04 11:52
leppie17-Jan-04 11:52 
QuestionHow do you think about delegate in c#? Pin
Forrest Feather17-Jan-04 9:50
Forrest Feather17-Jan-04 9:50 
AnswerRe: How do you think about delegate in c#? Pin
Forrest Feather17-Jan-04 9:56
Forrest Feather17-Jan-04 9:56 
AnswerRe: How do you think about delegate in c#? Pin
Nick Parker17-Jan-04 10:35
protectorNick Parker17-Jan-04 10:35 
AnswerRe: How do you think about delegate in c#? Pin
Heath Stewart17-Jan-04 10:57
protectorHeath Stewart17-Jan-04 10:57 
A delegate is a managed function pointer, and even offers several advantages. First, when compiled (for compilers that support this, as the C# compiler does) the compiler automatically generates asynchronous invocation methods! You can't beat that! Smile | :)

Take the following declarations in C:
BOOL CALLBACK EnumProc(LPCTSTR s);
BOOL EnumSomething(EnumProc proc);
In C#, this would look like:
public delegate bool EnumProc(string s);
// In some class...
public bool EnumSomething(EnumProc proc);
When you call EnumSomething, you would do so in a similar manner as with C:
bool val = EnumSomething(new EnumProc(MyEnumProc));
//...
private bool MyEnumProc(string s)
{
  Console.WriteLine(s);
}
In the implementation for EnumSomething, you could even use BeginInvoke instead of Invoke (or the shorthand way where you just use the delegate parameter like a function) for asynchronous invocation.

See Handling and Raising Events[^] and Including Asynchronous Calls[^] in MSDN for more information, in-depth topics, and plenty of examples.

Also, just so you can see there really isn't much different, when interop'ing methods that require a function pointer or P/Invoke functions that require function pointers, a delegate is what you use in lieu of an IntPtr. When the param is marshaled, it is marshaled as a function pointer.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: How do you think about delegate in c#? Pin
Colin Angus Mackay17-Jan-04 11:16
Colin Angus Mackay17-Jan-04 11:16 
GeneralRe: How do you think about delegate in c#? Pin
Heath Stewart17-Jan-04 11:19
protectorHeath Stewart17-Jan-04 11:19 
GeneralCheck if app is themed Pin
Roger Alsing17-Jan-04 8:56
Roger Alsing17-Jan-04 8:56 
GeneralRe: Check if app is themed Pin
Heath Stewart17-Jan-04 10:40
protectorHeath Stewart17-Jan-04 10:40 
GeneralA GDI+ Question Pin
muralidharck17-Jan-04 6:57
muralidharck17-Jan-04 6:57 
GeneralRe: A GDI+ Question Pin
Heath Stewart17-Jan-04 10:31
protectorHeath Stewart17-Jan-04 10:31 
GeneralRe: A GDI+ Question Pin
muralidharck17-Jan-04 14:40
muralidharck17-Jan-04 14:40 
GeneralExecutin Plugins Pin
CWIZO17-Jan-04 6:54
CWIZO17-Jan-04 6:54 
GeneralRe: Executin Plugins Pin
Heath Stewart17-Jan-04 10:21
protectorHeath Stewart17-Jan-04 10:21 
GeneralRe: Executin Plugins Pin
CWIZO17-Jan-04 22:13
CWIZO17-Jan-04 22:13 
Questionwhat kind of project Pin
gordingin17-Jan-04 6:38
gordingin17-Jan-04 6:38 
AnswerRe: what kind of project Pin
Heath Stewart17-Jan-04 10:16
protectorHeath Stewart17-Jan-04 10:16 
Generalchanging report at runtime Pin
H r M17-Jan-04 4:17
H r M17-Jan-04 4:17 
GeneralRe: changing report at runtime Pin
Heath Stewart17-Jan-04 10:13
protectorHeath Stewart17-Jan-04 10:13 
GeneralLimiting MDI child location Pin
phimix17-Jan-04 3:00
phimix17-Jan-04 3:00 
GeneralRe: Limiting MDI child location Pin
Amalorpavanathan Yagulasamy(AMAL)17-Jan-04 9:28
Amalorpavanathan Yagulasamy(AMAL)17-Jan-04 9:28 
GeneralRe: Limiting MDI child location Pin
phimix18-Jan-04 19:52
phimix18-Jan-04 19: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.