Can anyone explain Delegates in vb.net ?

  • Thread starter Thread starter Brad_1234
  • Start date Start date
  • Tags Tags
    Explain
Click For Summary
SUMMARY

Delegates in VB.NET are references to methods, functioning similarly to function pointers in C/C++. They enable runtime method invocation and are essential for event handling and callbacks in asynchronous programming. The discussion highlights the lack of clear explanations in existing examples, emphasizing the need for practical applications, such as invoking methods across different namespaces and classes. For effective usage, understanding the delegate constructor and variable instantiation is crucial.

PREREQUISITES
  • Understanding of VB.NET syntax and structure
  • Familiarity with namespaces and classes in VB.NET
  • Knowledge of asynchronous programming concepts
  • Basic understanding of event handling in programming
NEXT STEPS
  • Research "VB.NET delegate constructor" for detailed implementation
  • Explore "VB.NET asynchronous programming and callbacks" for practical examples
  • Investigate "VB.NET event handling" to understand delegate applications
  • Look up "VB.NET namespace usage" for accessing methods across classes
USEFUL FOR

VB.NET developers, software engineers working with asynchronous programming, and anyone looking to deepen their understanding of delegates and event handling in VB.NET.

Brad_1234
Messages
31
Reaction score
0
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 don't 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
 
Technology news on Phys.org
The OP hasn't been around for about 10 years, but in case someone else has a similar question...
Brad_1234 said:
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 let's 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 don't 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.
 
  • Like
Likes   Reactions: jim mcnamara

Similar threads

  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
63
Views
6K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
4
Views
4K
  • · Replies 36 ·
2
Replies
36
Views
5K
  • · Replies 5 ·
Replies
5
Views
15K