Can anyone explain Delegates in vb.net ?

  • Thread starter Brad_1234
  • Start date
In all the examples there is no explanation just code segments.

There is the delegate constructor and somewhere a variable is dimmed to the newly defined delegate type, then a second variable is dimmed, and it somehow works.

The variables most examples use have long names, the instantiated delegate sounds the same, the examples I find just dont explain the concept or how to use them.

Lets say there is a namespace with one class, and a method within that class that I want to call. from another namespace, different class, I want to run a method that can invoke a delegate and run the method in the first class

if there is a good explanation for vb.net delegates? Id appreciate hearing it

thanks
 
32,385
4,149
The OP hasn't been around for about 10 years, but in case someone else has a similar question...
In all the examples there is no explanation just code segments.
The short explanation is that a delegate is a reference to a method (in C/C++ parlance, a function pointer). The delegate concept is an advanced programming concept for which the main uses are being able to call a function at run time, as well is in responding to events. Delegates are also used in callbacks -- these are arguments in asynchronous methods where the callback is invoked when the asynchronous method has finished. This action lets the caller of the async function know that it has completed its task.
Brad_1234 said:
There is the delegate constructor and somewhere a variable is dimmed to the newly defined delegate type, then a second variable is dimmed, and it somehow works.

The variables most examples use have long names, the instantiated delegate sounds the same, the examples I find just dont explain the concept or how to use them.

Lets say there is a namespace with one class, and a method within that class that I want to call. from another namespace, different class, I want to run a method that can invoke a delegate and run the method in the first class

if there is a good explanation for vb.net delegates? Id appreciate hearing it
I'm not sure why you need a delegate for what you described. I haven't done any VB programming for a very long time, but the way it works in C# ought to be similar.

To use a method that belongs to a class in namespace NS, you would write a "using namespace NS;" statement in your program. If the class and its method are public, you would then have access to the class and its method. There would be a couple of ways to do this, depending on whether the class was defined as static or not.

For some examples, do a web search for "VB delegate examples" or "VB callback examples." That should get you some links to simple examples that you can play with.
 

Want to reply to this thread?

"Can anyone explain Delegates in vb.net ?" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top