Delegate A intend is a showcase-safe object that hardened up direct to another order (or possibly three-fold manners) in the application, which can be invoked at later time. A substitute type fend fors three important pices of reading : 1. The name of the mode on which it achieve calls. 2. Any stock (if any) of this method. 3. The restoration value (if any) of this method. define a Delegate in C# when you need to piddle a impute in C# you make drill of point keyword. The name of your delegate can be any(prenominal) you desire. However, you must define the delegate to mates the signature of the method it will point to. fo pillow slip 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.
Add); Â Â Â Â Â Â Â Â Â Â Â int pass onResult = del1(5, 5); Â Â Â Â Â Â Â Â Â Â Â Console.WriteLine(5 + 5 = {0}, addResult); Â Â Â Â Â Â Â Â Â Â Â MyDelegate del2 = new MyDe legate(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 recognise 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 compress 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.