3 ms·
Since we're all chipping in with features we'd like to see in C#, here are mine: anonymous classes - with actual class bodies, that can implement interfaces - a
by rmsaksida 10y ago
Since we're all chipping in with features we'd like to see in C#, here are mine: anonymous classes - with actual class bodies, that can implement interfaces - and traits.
- rjbwork 10y agoYou could, if you were so inclined, just generate proxies on the fly.
- voltagex_ 10y agoCan 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.
- flukus 10y agoOne 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 } });
- voltagex_ 10y agoI'm not convinced that gives you that much more over using a delegate.
- flukus 10y agoIt doesn't. It's a nice to have feature, not a world changing one.
- ygra 10y agoBut 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.
- tigershark 10y agomuch 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.
- yread 10y agoImplementation of IComparer
- daxfohl 10y agoYeah, coming from Java a decade ago this was the first thing I noticed lacking. And with all the stuff C# has introduced beyond that, I'm always fairly surprised that this hasn't been done. In preparation, the feature currently called "anonymous classes" in C# needs to be redubbed "anonymous records". And in preparation for that, well, "nonymous" records need to be introduced.