3 ms·
Delegates ... are essentially just syntactic sugar for a one-method class No that's not entirely true. There are a lot of similarities but there are essential
by DrJokepu 17y ago
Delegates ... are essentially just syntactic sugar for a one-method class
No that's not entirely true. There are a lot of similarities but there are essential differences as well. Delegates in .NET are truly functions as first class objects while single-method anonymous classes is Java are first class object wrappers around functions. This means that while in Java an anonymous class is a tuple with a reference to the instance of the anonymous class and a reference to the instance of the container class, in .NET it is a tuple with a reference (pointer actually) to a method and a reference to the instance of the owner class (if not static).
This is a subtle but important difference and is entrenched all the way down in the .NET type system, not just on syntax level.