.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> .NET Framework >> Post New QuestionBookmark and Share Subscribe to Forum

What is the use of delegate in .NET Framework?

Posted By: priya     Posted Date: December 03, 2009    Points:2   Category :.NET Framework
Hi Friends,

What is the use of delegate n .NET Framework? I am bit confused with this concept.

it would be better to have an example in C# because i am confirtable in C#

Thanks In Advance
Priya

Responses
Author: Amit Mehra             
Posted Date: December 04, 2009     Points: 5   

HI,


Callback functions are certainly one of the most useful programming mechanisms ever created. The C runtime's qsort function takes a callback function to sort elements within an array. In Windows, callback functions are required for window procedures, hook procedures, asynchronous procedure calls, and more. In the Microsoft .NET Framework, callback methods are used for a whole slew of things. You can register callback methods to get assembly load/unload notifications, unhandled exception notifications, database/window state change notifications, file system change notifications, menu item selections, completed asynchronous operation notifications, filtering a set of items, and so on.

you can find mire information here

http://msdn.microsoft.com/en-us/magazine/cc301810.aspx

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Abhisek Panda             
Posted Date: December 13, 2009     Points: 5   

A "delegate" is a type-safe object that points to another method in the application,which can be invoked at later time.More specifically a delegate type contains three important information,

1. The name of the method on which it makes calls.
2. The arguments o this method.
3. The return value of the method.


Once a delegate has been created and provided the required information, it may be dynamically invoke the methods it pointed to at runtime. Every .NET delegate is automatically endowed with the ability to call their methods synchronously or asynchronously.

For more detail refer to the following article,

http://www.dotnetspark.com/kb/1056-delegate-c-sharp.aspx

Author: Sagar Pardeshi             
Posted Date: February 26, 2010     Points: 5   

What is a Delegate?

When we talk about delegates in .NET then one thing that comes to our mind is what delegate means to a novice developer
. In simple words we can say delegates are a .NET object which points to a method that matches its specific signature.

In other words delegates are function pointers that point to function of matching signatures. Function pointers which are extensively used in c/c++ to points to a function holds only the memory address of the function, it doesn't carry further information about the function parameters, return type etc. On the other hand .NET framework has introduced a type-safe mechanism called delegates, with automatic verification of the signature by the compiler.

So comparatively delegates add a safety dimension in handling function pointers in .NET.

http://www.15seconds.com/issue/020815.htm
http://dotnetslackers.com/articles/net/Delegates-in-NET.aspx

Author: gsuryaprasath             
Posted Date: July 13, 2011     Points: 20   

[URL=http://www.cegonsoft.com/jobassistanceprogram.php]Delegates[/URL] are very similar to 'pointers to functions' in C and C++

First we create a delegate, then we can assign any function that has a similar prototype of the one which we have specified with the delegate.

Declaration:

public delegate int Dlg(int x, int y); //where Dlg is the name of Delegate

Create Object:
when we need to create a 'Delegate object' (i.e. a pointer to a function which has a specified prototype)

Dlg d1=new Dlg(function_name); //if the class is in some other class use 'class_name.function_name'

function_name->has to be the name of a function which receives two integers as arguments and return an integer

Invoking function:

int res=d1(20, 20);

Applications of Delegates
----------------------------------

used in event handling in C#.NET
i.e. we assign different event handler function to events like Click etc. Every event has a delegate object to represent its handler function.When we assign a function to an event handler, it is actually assigned to the corresponding delegate object and are invoked like in the above example.

[URL=http://www.aboutcegonsoft.com/]Cegonsoft[/URL]



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend