Click here to Skip to main content
15,918,889 members
Home / Discussions / C#
   

C#

 
GeneralRe: accessing properties of the mdiParent from the child Pin
Skynyrd8-Feb-05 11:56
Skynyrd8-Feb-05 11:56 
GeneralDataGrid Cell being edited Pin
Keith La Force6-Feb-05 9:55
Keith La Force6-Feb-05 9:55 
GeneralRe: DataGrid Cell being edited Pin
Christian Graus6-Feb-05 14:40
protectorChristian Graus6-Feb-05 14:40 
GeneralRe: DataGrid Cell being edited Pin
Luis Alonso Ramos6-Feb-05 17:55
Luis Alonso Ramos6-Feb-05 17:55 
GeneralRe: DataGrid Cell being edited Pin
Keith La Force7-Feb-05 1:16
Keith La Force7-Feb-05 1:16 
GeneralGetOpenFileName in C# Pin
Formato6-Feb-05 9:01
Formato6-Feb-05 9:01 
GeneralRe: GetOpenFileName in C# Pin
Heath Stewart7-Feb-05 6:15
protectorHeath Stewart7-Feb-05 6:15 
GeneralEvents and delegates: help! Pin
Gleb Belov6-Feb-05 4:55
Gleb Belov6-Feb-05 4:55 
Hello!

I've been programming in C# for about a month now with a book called Beginning Visual C#.NET (Wrox Press). So yesterday I got to the Events chapter and...

I really need your help!

In this book the author sais and explains that events are used with delegates.
So you kind of use both...

But I can't get it: why are they used with delegates? How do you put them together?

I can undestand events like this (used from a thread nearby...) with no problems:
private void AddButtons()
{
Button B1 = new Button();
B1.Text = "OK";
B1.Location = new System.Drawing.Point(8,8);
B1.Click += new System.EventHandler(buttonB1Click);
}

private void buttonB1Click(object sender, System.EventArgs e)
{
MessageBox.Show("Hello");
}
------
I can understand delegates like this (example from my book):
class Class1
{
delegate double processDelegate(double param1, double param2);

static double Multiply(double param1, double param2)
{
return param1 * param2;
}

static double Devide(double param1, double param2)
{
return param1 * param2;
}

///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
processDelegate process;
Console.WriteLine("Enter 2 numbers separated with a comma:");
string input = Console.ReadLine();
int commaPos = input.IndexOf(',');
double param1 = Convert.ToDouble(input.Substring(0, commaPos));
double param2 = Convert.ToDouble(input.Substring(commaPos + 1,
input.Length - commaPos - 1));
Console.WriteLine("M for multiply, D for devide:");
input = Console.ReadLine();
if (input == "M")
process = new processDelegate(Multiply);
else
process = new processDelegate(Devide);
Console.WriteLine("Result {0}", process(param1, param2));
}
}
}
-----------------------
But I CANNOT undestand what do they have to do with each other? Why use them, when I can use events like in the example above? What do delegates do that helps with events?

Please, explain thoroughly in a non-article dummy-undestandble way, as I have read a lot of articles on it today, but still it seems that in all of them it's a given...

Please! Because I really need to move on, but I can't since I cannot undestand
the topic!

If you want, I can kindly 'reward' you with a Gmail account, no probs with that! But please help!

Thanks!
GeneralRe: Events and delegates: help! Pin
mav.northwind6-Feb-05 5:12
mav.northwind6-Feb-05 5:12 
GeneralRe: Events and delegates: help! Pin
Gleb Belov6-Feb-05 5:37
Gleb Belov6-Feb-05 5:37 
GeneralRe: Events and delegates: help! Pin
Skynyrd6-Feb-05 6:17
Skynyrd6-Feb-05 6:17 
GeneralEventHandler question! Pin
QzRz6-Feb-05 1:50
QzRz6-Feb-05 1:50 
GeneralRe: EventHandler question! Pin
mav.northwind6-Feb-05 3:11
mav.northwind6-Feb-05 3:11 
GeneralRe: EventHandler question! Pin
Heath Stewart6-Feb-05 7:24
protectorHeath Stewart6-Feb-05 7:24 
Generalcreate a Byte[] array Pin
Sasuko6-Feb-05 0:19
Sasuko6-Feb-05 0:19 
GeneralRe: create a Byte[] array Pin
Robert Rohde6-Feb-05 0:56
Robert Rohde6-Feb-05 0:56 
GeneralRe: create a Byte[] array Pin
Sasuko6-Feb-05 1:27
Sasuko6-Feb-05 1:27 
Generalremote user name Pin
Opa Knack6-Feb-05 0:12
Opa Knack6-Feb-05 0:12 
GeneralRe: remote user name Pin
Heath Stewart6-Feb-05 7:21
protectorHeath Stewart6-Feb-05 7:21 
QuestionCreating MMC snap-in? Pin
esjq5-Feb-05 23:33
esjq5-Feb-05 23:33 
AnswerRe: Creating MMC snap-in? Pin
Heath Stewart6-Feb-05 7:18
protectorHeath Stewart6-Feb-05 7:18 
GeneralRe: Creating MMC snap-in? Pin
esjq6-Feb-05 20:53
esjq6-Feb-05 20:53 
Generalupdate doesn't update database Pin
xrado5-Feb-05 23:14
xrado5-Feb-05 23:14 
GeneralRe: update doesn't update database Pin
Heath Stewart6-Feb-05 7:10
protectorHeath Stewart6-Feb-05 7:10 
GeneralEditing custom file formats Pin
Gleb Belov5-Feb-05 22:48
Gleb Belov5-Feb-05 22:48 

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.