delegate - part 1

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

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


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

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)

Fernando SotoRetiredCommented:
hI VBdotnet2005;

Here is a site on delegates:

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

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.