Sergey Gromov wrote:
Tue, 04 Aug 2009 22:46:22 +1000, Daniel Keep wrote:

Sergey Gromov wrote:
Tue, 04 Aug 2009 17:22:50 +1000, Daniel Keep wrote:

Don wrote:
...

A question: in C#/Java, can you have annotations on function pointer and
delegate declarations?

void foo( int delegate(int) pure dg) {
  ...
}
What would this look like with annotations?
Well, Java doesn't HAVE delegates and C# doesn't (AFAIK) allow you to
define them inline; they have a special declaration syntax that can't be
used in an expression.
C#:

List<int> ls;
ls.Sort((x, y) => y - x);

or

ls.Sort((x, y) => { int a; a = y; a -= x; return a; });
That's not a delegate type, that's a delegate literal.

Sorry, you said: "C# doesn't ... allow you to define them (delegates)
inline".  Delegate literal *is* an inline definition of a delegate.
What you say now is that C# doesn't allow to define a delegate type
inside a function which is definitely true and is very annoying.

Have you seen the Func delegates? They are exactly for that.

The above example would be:

void foo(Func<int, int> dg) { ... }

Reply via email to