C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Delegates


Posted Date: 12 Nov 2008    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: shekharMember Level: Gold    
Rating: 1 out of 5Points: 10



A delegate is an object that can refer to a method.
The method referenced by delegate can be called through the delegate.
A delegate in C# is similar to a function pointer in C/C++.
The same delegate can call different methods.
A delegate is declared using the keyword delegate.

The general form of a delegate declaration:

delegate ret-type name(parameter-list);

ret-type is return type.
The parameters required by the methods are specified in the parameter-list.

A delegate can call only methods whose return type and parameter list match those specified by the delegate's declaration.

All delegates are classes that are implicitly derived from System.Delegate.


using System;


delegate void FunctionToCall();

class MyClass
{
public void nonStaticMethod()
{
Console.WriteLine("nonStaticMethod");
}

public static void staticMethod()
{
Console.WriteLine("staticMethod");
}
}

class MainClass
{
static void Main()
{
MyClass t = new MyClass();
FunctionToCall functionDelegate;
functionDelegate = t.nonStaticMethod;

functionDelegate += MyClass.staticMethod;
functionDelegate += t.nonStaticMethod;
functionDelegate += MyClass.staticMethod;

functionDelegate();
}
}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Delegates  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Caching in ASP.Net
Previous Resource: Creating the Backups for wss projects in sharepoint
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use