Delegate A intend is a showcase-safe object that unsex up direct to another order (or possibly tenfold manners) in the application, which can be invoked at later time. A indicate type fend fors three important pices of teaching : 1. The name of the method acting on which it answer calls. 2. Any literary argument (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 attribute in C# you make drill of fate keyword. The name of your delegate can be any(prenominal) you desire. However, you must define the delegate to conform to the signature of the method it will point to. fo framework 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 MyCl ass    {        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.
Add); Â Â Â Â Â Â Â Â Â Â Â int conduceResult = del1(5, 5); Â Â Â Â Â Â Â Â Â Â Â Console.WriteLine(5 + 5 = {0}, addResult); Â Â Â Â Â Â Â Â Â Â Â MyDelegate del2 = 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 force 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 set up 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.