C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




delegates


Posted Date: 28 Aug 2008      Total Responses: 2

Posted By: narendra       Member Level: Silver     Points: 1


hi freinds plz help me

Delegate declaration defines a reference type that can be used to encapsulate a method with a specific signature




Responses

Author: Legend     29 Aug 2008Member Level: SilverRating:     Points: 6
A delegate declaration defines a reference type that can be used to encapsulate a method with a specific signature. A delegate instance encapsulates a static or an instance method. Delegates are roughly similar to function pointers in C++; however, delegates are type-safe and secure.

This declaration takes the following form::

attributes (Optional)
Additional declarative information. For more information on attributes and attribute classes, see 17. Attributes.
modifiers (Optional)
The allowed modifiers are new and the four access modifiers.
result-type
The result type, which matches the return type of the method.
identifier
The delegate name.
formal-parameters (Optional)
Parameter list. If a parameter is a pointer, the delegate must be declared with the unsafe modifier.

Example 1

// keyword_delegate.cs
// delegate declaration
delegate void MyDelegate(int i);

class Program
{
public static void Main()
{
TakesADelegate(new MyDelegate(DelegateFunction));
}

public static void TakesADelegate(MyDelegate SomeFunction)
{
SomeFunction(21);
}

public static void DelegateFunction(int i)
{
System.Console.WriteLine("Called by delegate with number: {0}.", i);
}
}


Output
Called by delegate with number: 21.





Author: Athira Appukuttan    29 Aug 2008Member Level: DiamondRating:     Points: 6
Hi..

Delegates add a safety to the idea of traditional function pointers. The .NET framework has added the bonus of providing a type-safe mechanism called delegates. They follow a Trust-But-Verify model, with automatic verification of the signature by the compiler. Unlike function pointers however, delegates are object-oriented, type-safe, and secured. In short, a delegate is a data structure that refers to a static method or to an object instance, and an instance method of that object. When the delegate references an instance method, it stores not only a reference to the method entry point, but also a reference to the object instance for which to invoke the method.

For more..

http://www.codeproject.com/KB/vb/Delegate.aspxhttp://www.aspnettutorials.com/tutorials/advanced/delegate-aspnet2-csharp.aspx



Post Reply
You must Sign In to post a response.
Next : constructor
Previous : VB.net to C# conversion is not working
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use