Press "Enter" to skip to content

The (first) thing annoying about C#

[I haven’t gotten too far into the language so I can’t presume there won’t be more…]

I *want* to like C#. I think it has a lot of advantages over the widely used languages that come before it. When it was first released, it was widely believed to be a replacement for Java; but I’m looking at it more as a replacement for C++ — the little things that are peculiar idioms or complex constructs in C++ seem to tend to be directly supported in C#. So I’m predisposed to like it.

But then I come across these annoying Microsoft-isms — specifically, the Humpty-Dumpty-like [1] way in which they define ordinary computing terms like “events” and “delegates” to be something almost, but not quite, completely different.

I know what a “delegate” is — it’s an object that handles behavior for another object. A common design pattern, and one supported pretty much directly in Objective-C and Cocoa. But that’s not what a C# delegate is, apparently — although I’m not sure exactly what it’s supposed to be. It’s “like a function pointer”, except we don’t have those in C#. And the first example I see (in [*Mono: A Developer’s Handbook*]( suggests that the thing you declare as a delegate is really a prototype for the action that the actual thing you instantiate is supposed to take — huh? Wouldn’t *that* be the delegate?

And apparently an “event” is a collection of delegates, and not, well, an event.

And somehow delegates are magic so you can instantiate one, add it to an “event”, then later instantiate a *different* one and *remove* it from the *same* event, and the “right thing” happens. (Because they’re “like function pointers”.)

Maybe this will make sense if I keep reading. (I hesitate to crack open [*The C# Programming Language*](, which is also on my desk; I’m a bit of a programming language nut, but this one looks like I need a law degree to get through it.)

[1] I could have said “Orwellian”; aren’t you proud of me?

Comments are closed.