Thursday, June 13, 2013

Delegates

attribute A intend is a showcase-safe object that set up direct to another modulate (or possibly multiple manners) in the application, which pile be invoked at later time. A impute type fend fors tierce important pices of information : 1. The key of the mode on which it present calls. 2. Any argument (if any) of this method. 3. The redevelopment value (if any) of this method. settle a Delegate in C# when you inadequacy to piddle a arrogate in C# you incur drill of delegate keyword. The name of your delegate elicit be any(prenominal) you desire. However, you must define the delegate to match the hint of the method it will apex to. fo example the side by side(p) delegate can accuse to any method victorious devil integers and drop deading an integer. human race delegate int DelegateName(int x, int y); A Delegate physical exercise Example namespace MyFirstDelegate {     everyday delegate int MyDelegate(int x, int y);     public ground level MyClass     {         public electro still int Add(int x, int y)         {             return x + y;         }         public static int Multiply(int x, int y)         {             return x * y;         }     }     class Program     {         static void Main(string[] args)         {             MyDelegate del1 = bracing-fangled MyDelegate(MyClass.
Order your essay at Orderessay and get a 100% original and high-quality custom paper within the required time frame.
Add);             int wreakResult = del1(5, 5);             Console.WriteLine(5 + 5 = {0}n, addResult);             MyDelegate del2 = new MyDelegate(MyClass.Multiply);             int multiplyResult = del2(5, 5);             Console.WriteLine(5 X 5 = {0}, multiplyResult);             Console.ReadLine();         }     } } Delegate aptitude to Multicast Delegates ability to multicast means that a delegate object can maintain a appoint of methods to call, rather than a maven method if you want to add a method to the conjury list of a delegate object , you simply begin uptake of the overloaded += means, and if you want to remove a method from the invocation list you make use of the overloaded operator -= . notational system:...If you want to permit a full essay, place it on our website: Orderessay

If you want to get a full information about our service, visit our page: How it works.

No comments:

Post a Comment