delegate - part 1

Could someone explain what the heck it delegate and provide a sample?  I'm confused.
VBdotnet2005Asked:
Who is Participating?
 
PockyMasterCommented:
A delegate is merely a function pointer.

With a delegate you describe what a function you can call from 'another place' looks like

e.g.

public delegate sub MyDelegate(var as String)

Meaning: the function you are passing will look like:
sub MyDelegate(var as String)


You can create vars of that type and call it like a function:
dim myDel as MyDelegate

myDel("werwer")
NOTE: myDel needs to be instantiated first:

e.g. from your class that actually contains the real method:

dim myDelegateClass as new myDelegateClass
myDelegateClass.SetMyDelegate(Addressof MySubThatLooksTheSameLikeMyDelegate)

And in this class you will have a method like:

private sub MySubThatLooksTheSameLikeMyDelegate (werwer as String)

....
0
 
Mikal613Commented:
0
 
Fernando SotoRetiredCommented:
hI VBdotnet2005;

Here is a site on delegates:

A Beginner's Guide to Delegates:
Has downloadable VB .Net Project showing its use.

    http://www.codeproject.com/vb/net/Delegate.asp#xx1428967xx

Fernando
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.