Delegate, DOT NET Programming

Assignment Help:

What is a delegate?

The Delegate is the class that can hold a reference to a method or a function. The Delegate class has a signature and it can only reference to those methods whose signature is compliant with the class. The Delegates are type-safe functions pointers or callbacks.

The sample code is shown below which shows an example of how to implement delegates.

Public Class FrmDelegates

Inherits System.Windows.Forms.Form

Public Delegate Sub DelegateAddString()

Private Sub FrmDelegates_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub AddString()

lstDelegates.Items.Add("Running AddString() method") End Sub

Private Sub cmdDelegates_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelegates. Click

Dim objDelegateAddString As DelegateAddString objDelegateAddString = AddressOf AddString objDelegateAddString.Invoke()

End Sub

End Class

In the above code there is a method called "AddString()" that adds a string to a listbox. You can also view a delegate declared as:-

Public Delegate Sub DelegateAddString()

This delegate signature is compatible with all the "AddString" method. When I say compatibility that means that there return types and passing parameter types are similar. After in command click of the button object of the Delegate is created and the method pointer is received from "AddressOf" keyword. Then by using "Invoke" method the method is invoked.

 

668_delegate.png

Figure:-Delegate in Action


Related Discussions:- Delegate

How to use activex control in .net, How to use ActiveX Control in .Net ? ...

How to use ActiveX Control in .Net ? ActiveX control is a special type of COM component  that supports a User Interface. Using ActiveX Control in your .Net Project is even

Program, finding greatest of n no''s in c#

finding greatest of n no''s in c#

Marshalling and types of marshalling, What is marshalling and types of mars...

What is marshalling and types of marshalling? The Marshaling is used when an object is converted so that it can be sent across the network or across the application domains. Th

Codedom, What is CodeDom The "CodeDom" is an object model that represen...

What is CodeDom The "CodeDom" is an object model that represents actually a source code. It is designed for language independent - once you create a "CodeDom" hierarchy for a p

Need help to answer questions of vb.net, Project Description: Need help ...

Project Description: Need help to answer questions of VB.NET Skills required are .NET, Software Development, C# Programming, Visual Basic, Windows Desktop

#title., what are major difference between classic ADO &ADO.NET?

what are major difference between classic ADO &ADO.NET?

Wowza expert required, Wowza expert required Project Description: See...

Wowza expert required Project Description: Seeking wowza expert to teach our webmaster. To provide: How configure wowza to live transcoder. How allow add live transc

Specify session state mode in asp.net, cookieless="false" timeout="20" ...

cookieless="false" timeout="20" /> Above is sample session state mode specified for SQL SERVER.

What is the use of a global.asax file in asp.net, Question: (a) Outlin...

Question: (a) Outline four classes that allow you to work with File Streams. (b) (i) What potential problem can arise when you change items stored in an Application State

Steps to create a windows service in vb.net, What are the steps to create a...

What are the steps to create a windows service in VB.NET ? The Windows Services are long-running executable applications that run in its own Windows session, which then has the

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd