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 !




Multi-Cast delegates


Posted Date: 09 Jul 2007    Resource Type: Code Snippets    Category: Event Handling

Posted By: daya       Member Level: Gold
Rating:     Points: 7



In this section of code i'll demonstrate how to call many methods at runtime associated with that particular delegate.




using System;
using System.Collections.Generic;
using System.Text;

namespace DelegatesHandling
{
public delegate decimal Calculator(decimal num1, decimal num2);
public delegate void Test(string str);

class Program
{
Calculator claci_1;
Calculator claci_2;
Calculator calci;

decimal Addition(decimal n1,decimal n2)
{
return n1 + n2;
}

decimal Subtraction(decimal n1, decimal n2)
{
return n1 - n2;
}

void TestMethod1(string str)
{
Console.WriteLine("I am in TestMethod1 "+str);
}

void TestMethod2(string str)
{
Console.WriteLine("I am in TestMethod2 " + str);
}

static void Main(string[] args)
{

Program pgm = new Program();
pgm.claci_1 = new Calculator(pgm.Addition);
pgm.claci_2 = new Calculator(pgm.Subtraction);

pgm.calci = new Calculator(pgm.Subtraction);
pgm.calci += new Calculator(pgm.Addition);


decimal result = pgm.claci_1(12.23m, 344.422m);
Console.WriteLine("Addition = "+result);

result = pgm.claci_2(12.23m, 344.422m);
Console.WriteLine("Subtraction = " + result);

result = pgm.calci(12.2m,13.8m);
Console.WriteLine("Subtraction = " + result);

Console.ReadLine();


}
}
}







Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

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: Handling events & delegates with code example
Previous Resource: Allow Numericals in a TextBox Control
Return to Discussion Resource Index
Post New Resource
Category: Event Handling


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call definitions

Contact Us    Privacy Policy    Terms Of Use