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

Design a integrated application, This assignment aims to give you a deeper...

This assignment aims to give you a deeper understanding of a 3-tiers integrated application, which groups together several topics taught in this course. This assignment asks yo

Explain some built-in functions of vbscript, Problem: (a) Explain the ...

Problem: (a) Explain the difference between these two lines of ASP codes: (b) The VBScript language includes some built-in functions which are often used in ASP co

I want a c# school project, I want a C# school project Project Descripti...

I want a C# school project Project Description: The project is made in C# and haves a database connection. We have some small problems asking up data from the database.

Print triangle in reverse pattern - c# program, Print Triangle in Reverse P...

Print Triangle in Reverse Pattern - C# Program Need the code of C# Program for Print Triangle in Reverse Pattern.

Explain in brief dataadapter class in ado.net, Explain in brief DataAdapter...

Explain in brief DataAdapter class in ADO.NET. The DataAdapter class retrieves data from the database, keeps data in a dataset, and reflects the changes made in the dataset to

Define assembly-types of assembly, Assembly: 1) Assembly is a unit of d...

Assembly: 1) Assembly is a unit of deployment such as EXE or a DLL. 2) An assembly consists one or more files (dlls, exe's, html files etc.),& represents a group of resources,

I need isometric exploration tablet game, I need Isometric Exploration Tabl...

I need Isometric Exploration Tablet Game I am endeavoring to build an 2D tile-based isometric game, primarily for Android and iOS tablet devices. It will be built in Unity 3d v4

Finding maximum & minimum numbers - c# program, Finding Maximum & Minimum N...

Finding Maximum & Minimum Numbers - C# Program I am facing some problems in the code for Finding Maximum & Minimum Numbers. Can anybody suggest me the proper code for it.

Develop a simple .net software, I am seeking someone who can design customi...

I am seeking someone who can design customized software for me, preferably in .NET. I have a sql server backend which i would like to use so you only have to work with the front en

Tutoring, Hi, I have been working on Dot Net over the past few years. I wou...

Hi, I have been working on Dot Net over the past few years. I would like to do online tutoring for .NET. Could you please let me know the possible oppurtunities

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