|
-
July 12th, 2007, 05:03 AM
#1
Delegates
I have a book that says:-
a delegate may be defined in the following places:-
1) Inside a class - ok!
2) Outside all classes - ok!
3) As a top level object in a namespace - huh??
please can some1 throw light on 3rd?
-
July 12th, 2007, 05:47 AM
#2
Re: Delegates
Perfectly legal. You can see the Delegate like a blueprint ( or like a class ) . First you declare it and then you instantiate it. You don't need to declare it in a class.
Code:
namespace WindowsApplication1
{
publicdelegatevoidMyDelegate();
publicpartialclassForm1 : Form
{
MyDelegate del;
privatevoid DoNothing()
{
MessageBox.Show("nothing");
}
public Form1()
{
InitializeComponent();
del = newMyDelegate(DoNothing);
}
}
}
Bogdan
If someone helped you then please Rate his post and mark the thread as Resolved
Please improve your messages appearance by using tags [ code] Place your code here [ /code]
-
July 12th, 2007, 08:11 AM
#3
Re: Delegates
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|