站内搜索: 请输入搜索关键词
当前页面: 图书首页 > NET For Java Developers Migrating To C#

NET For Java Developers Migrating To C#

[ directory ] Previous Section Next Section

Chapter 18. Delegates and Event Programming

This chapter explores one of the new constructs of C# that has no equivalent in the Java programming language. C#'s language API is peppered with uses of this construct. If you examine the threading and I/O APIs, you'll find that the entire asynchronous callback mechanism is based on this new construct, which is called delegates.

Another reason for the support of delegates in C# concerns function pointers, which have been a popular construct in C++ and C but are not supported in Java. Because Java treats everything as a class, the makers of Java did not find the need for a separate construct for function pointers. C#, however, was not meant to lure only Java programmers. C#'s delegates make C and C++ programmers feel at home. Delegates are essentially references to a function (instead of an object) that can be called. Just like a regular object reference, this reference to a function can be an instance reference, static, or a property.

    [ directory ] Previous Section Next Section