Hacker News new | past | comments | ask | show | jobs | submit login

Can you give an example of how C# would be different with anonymous classes?

Googling that term just gives a whole lot of references to inner classes in Java.

Implementation of IComparer

One I've come across is binding a command to a button. With anonymous inner classes you can have something like:

  myButton.AddListener(new Command {
    bool enabled() {
      return false; //more logic goes here
    void onClick() {
      //do something

But that's something that's very rare in C#. Usually for that sort of thing you have events and delegates. Although I have to admit that the library I work on had a few patterns that would benefit from anonymous interface implementations, but not that much to really miss the feature.

much much better to use DelegateCommand:

    SubmitCommand = new DelegateCommand(()=> DoSomething(), ()=> IsSubmitEnabled);
Edit: and obviously the Command DependencyProperty on the Button will be bound to the SubmitCommand property, instead of accessing directly the button from the ViewModel, that is the worst possible thing that you can possibly do.

I'm not convinced that gives you that much more over using a delegate.

It doesn't. It's a nice to have feature, not a world changing one.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact