Click here to Skip to main content
15,879,535 members
Home / Discussions / C#
   

C#

 
GeneralRe: C # API Pin
Kannan Kalyanaraman10-Sep-03 22:06
Kannan Kalyanaraman10-Sep-03 22:06 
GeneralChild Hide/Show Problem Pin
Clarke7610-Sep-03 19:17
Clarke7610-Sep-03 19:17 
QuestionUnregister an assembly? Pin
Bog10-Sep-03 17:02
Bog10-Sep-03 17:02 
AnswerRe: Unregister an assembly? Pin
Nick Parker10-Sep-03 18:16
protectorNick Parker10-Sep-03 18:16 
GeneralRe: Unregister an assembly? Pin
Bog11-Sep-03 7:29
Bog11-Sep-03 7:29 
GeneralDelegates Pin
deanoA10-Sep-03 15:49
deanoA10-Sep-03 15:49 
GeneralRe: Delegates Pin
Blake Coverett11-Sep-03 7:33
Blake Coverett11-Sep-03 7:33 
GeneralRe: Delegates Pin
Blake Coverett11-Sep-03 7:36
Blake Coverett11-Sep-03 7:36 
The shortest example? Well I guess that would be...
class T{delegate void D();static void Main(){new D(Main)();}}
...but watch out for the stack overflow.

I suppose you'd like a useful example?
class Example {
	delegate void StatusOutput(string text);

	static void Main() {
		DoSomeWork(new StatusOutput(System.Console.WriteLine));
		DoSomeWork(new StatusOutput(Alert));
	}

	static void Alert(string text) {
		System.Windows.Forms.MessageBox.Show(text, "Status Update");
	}

	static void DoSomeWork(StatusOutput output) {
		output("Working...");
		System.Threading.Thread.Sleep(2000);
		output("Done");
	}
}

That was about the shortest meaningful use I could think of. A delegate is an object that wraps a method. You can then pass this object around and use it later to call the method. There are lots of other more advanced uses, like invoking them asynchronously, but that's a start.

--
-Blake (com/bcdev/blake)
GeneralRef in C# Pin
deanoA10-Sep-03 15:41
deanoA10-Sep-03 15:41 
GeneralRe: Ref in C# Pin
J. Dunlap10-Sep-03 15:44
J. Dunlap10-Sep-03 15:44 
GeneralDataGridColumnStyle Pin
Giant Penguin10-Sep-03 14:57
Giant Penguin10-Sep-03 14:57 
GeneralRe: DataGridColumnStyle Pin
sumeat11-Sep-03 15:04
sumeat11-Sep-03 15:04 
Generalcolor combobox Pin
monrobot1310-Sep-03 14:55
monrobot1310-Sep-03 14:55 
GeneralRemoting and using statements Pin
babarfloyd10-Sep-03 13:17
babarfloyd10-Sep-03 13:17 
GeneralRe: Remoting and using statements Pin
monrobot1310-Sep-03 17:04
monrobot1310-Sep-03 17:04 
GeneralRe: Remoting and using statements Pin
babarfloyd15-Sep-03 7:25
babarfloyd15-Sep-03 7:25 
Generalcustom paging through a DataView Pin
clayne10-Sep-03 10:09
clayne10-Sep-03 10:09 
QuestionCreating a .tif tag with PropertyItem? Pin
RHamilton10-Sep-03 9:33
RHamilton10-Sep-03 9:33 
GeneralKeyboard hook + C# problem Pin
Ylis10-Sep-03 9:28
Ylis10-Sep-03 9:28 
GeneralRe: Keyboard hook + C# problem Pin
Donald_a10-Sep-03 23:51
Donald_a10-Sep-03 23:51 
GeneralRe: Keyboard hook + C# problem Pin
Donald_a10-Sep-03 23:56
Donald_a10-Sep-03 23:56 
GeneralRe: Keyboard hook + C# problem Pin
Ylis11-Sep-03 5:05
Ylis11-Sep-03 5:05 
GeneralRe: Keyboard hook + C# problem Pin
Anonymous12-Sep-03 6:01
Anonymous12-Sep-03 6:01 
Generalconvert ASCII into char Pin
devvvy10-Sep-03 7:17
devvvy10-Sep-03 7:17 
GeneralRe: convert ASCII into char Pin
Julian Bucknall [MSFT]10-Sep-03 8:50
Julian Bucknall [MSFT]10-Sep-03 8:50 

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.