The true face of the commission in my Eyes (iii)

Source: Internet
Author: User

In fact, I am afraid everyone after reading (a) has in mind produced a ready to think-the delegate is the function of the pointer! At first, I had this idea, but I did not find support in the corresponding literature. This is something, however, when my own understanding of the entrustment arrives to be able to write the first essay. Therefore, a few of the previous although called "the true face of the commission in my eyes" is actually my own for the commissioned a process of exploration, so I commissioned a common and more representative of several usages to organize the context of the article. Personal feeling, for an unknown object, such a process is actually very necessary. At the very least, I hope that I can help those friends who are not too familiar with the delegates to take some detours.

However, the idea of the idea, I said for the time being not found the corresponding theoretical support. Therefore, I still to explore the attitude of some of my views, welcome to criticize, and hope that has been fully acquainted with the entrusted mechanism of the high people do not hesitate to enlighten.

Not long ago, an accidental opportunity to search for such an article:

From function pointers to proxies (Getting started with C # agent)

The author is wood like a friend. He explained to us in the text that a delegate is an extension of the function pointer function.

In fact, the personal feeling of this statement to clarify the point of view there is a certain reason, interested friends can support the wood like a friend of the post. Whether this view is correct or not, let's not. However, we can use this as a topic to explore the function of the delegate ratio of the function of the pointer on what the extension.

In C # to understand some of the characteristics of an object itself is very simple, we do not even need to rely on MSDN, you only need to declare the corresponding object, after this point a ".", the C # compiler's IntelliSense will automatically list the object's related properties and some simple description of its methods.

With an instantiated delegate object, we can get a general idea of some of the specific methods and properties of the delegate object. Here we discuss how to use several key methods:

9. Implementation of asynchronous delegates

using System.Threading;

namespace AsyncDelegate
{
    class Program
    {
        //定义委托
        delegate void MyDelegate();

        static void Main(string[] args)
        {

            //声明委托对象
            MyDelegate ObjDelegate = new MyDelegate(ObjDelegateFun);

            //使用异步方式
            IAsyncResult ObjIr = ObjDelegate.BeginInvoke(null,null);
            Console.WriteLine("委托方法执行中.");
            Thread.Sleep(5000);
            ObjDelegate.EndInvoke(ObjIr);
            Console.ReadLine();
        }

        static private void ObjDelegateFun()

        {
            Thread.Sleep(5000);

            Console.WriteLine("委托方法调用成功!");
        }
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.