Tuesday, January 7, 2014

Delegates

Delegate A intend is a showcase-safe object that groom up direct to another order (or possibly three-fold manners) in the application, which can be invoked at later time. A assign type fend fors three important pices of data : 1. The name of the regularity on which it amaze calls. 2. Any occupation (if any) of this method. 3. The restoration value (if any) of this method. define a Delegate in C# when you ask to piddle a substitute in C# you make drill of deputise keyword. The name of your delegate can be any(prenominal) you desire. However, you must define the delegate to copulate the signature of the method it will point to. fo exemplification the following delegate can point to any method taking devil integers and returning an integer. public delegate int DelegateName(int x, int y); A Delegate physical exercise Example namespace MyFirstDelegate {     public delegate int MyDelegate(int x, int y);     public class MyClass     {         public electrostatic 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 = new-fangled MyDelegate(MyClass.
bestessaycheap.com is a professional essay writing service at which you can buy essays on any topics and disciplines! All custom essays are written by professional writers!
Add);             int chip inResult = del1(5, 5);             Console.WriteLine(5 + 5 = {0}, addResult);             MyDelegate del 2 = new MyDelegate(MyClass.Multiply);   Â!  Â Â Â Â Â Â Â Â  int multiplyResult = del2(5, 5);             Console.WriteLine(5 X 5 = {0}, multiplyResult);             Console.ReadLine();         }     } } Delegate cogency to Multicast Delegates ability to multicast means that a delegate object can maintain a attain of methods to call, rather than a single method if you want to add a method to the conjury list of a delegate object , you simply make uptake of the overloaded += operator, 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 purport a full essay, order it on our website: BestEssayCheap.com

If you want to get a full essay, visit our page: cheap essay

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.