CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Delegates

  1. #1
    Join Date
    Jul 2007
    Posts
    28

    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?

  2. #2
    Join Date
    Mar 2006
    Location
    Craiova, Romania
    Posts
    439

    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]

  3. #3
    Join Date
    Jul 2007
    Posts
    28

    Thumbs up Re: Delegates

    thanx !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured