Another cool feature of C# is the inclusion of Delegates. Again this is something that can be implemented in C++ but it is good to have it directly supported by the language. I still have to get to the chapters on the libraries that are a part of C#, but I hope that delegates are how events in the GUI are handled.
This means that you could register for events on a Window without having to sub-class that Window. This is a powerful concept and not one directly supported in MFC, which is why I wrote my own C++ GUI class library to wrap the Win32 API. At the time I wrote that library I refered to this as Behavior-Oriented programming.
I was mistaken for being Jewish, again. I do not mind at all. I just don't understand how I, an Italian catholic originally from Connecticut, appear Jewish. This has happened to me several times in the past and wouldn't normally be worth mentioning but I can't help thinking about what turns out to be a simple mistake here in the U.S. could end up getting me killed in some other county.
I am a bit peeved about my purchase of C# Essentials, not with O'Reilly or with the authors but with Barnes&Noble. Seems I bought the out-of-print First Edition of C# Essentials, not the new and updated Second Edition. So do I have a collectors item? Probably not since within a half hour of getting it home it had a wrinkled cover, ripped page, and magic marker on the outside. Yes, I have a two year old son...
In fact, I have never looked at Java. In my career I have never had a need to look at it. I have split my time evenly between writing Windows only scientific/control applications and writing firmware for embedded applications (DSPs, 68HC11, 8051, 80386 and PICs).
I am reading C# Essentials. I have to admit that I am impressed with the design of C#. I was expecting a watered-down version of C++ and instead many of the features of C# are direct fixes for problems or rough spots in C++. Genamics has a good comparison of C++ to C# so I won't repeat the points of that article instead I will point out cool things about C# that they do not cover.
The first is the handling of virtual functions. To make a function virtual in a base class you use the 'virtual' keyword in the declaration of the function just like you do in C++. The difference comes when you declare a subclass and want to override that virtual function. In C++ you declare the overriding function as virtual just like it is in the parent class. In C# you use the 'override' keyword. This fixes a major problem that exists with C++, that is, if you are looking at a class in isolation and see a virtual function you have to go digging to determine if it is overriding a base class function or if it is starting a new virtual function.
Nested types are cool and should have been part of C++.
Static constructors are also very cool. A single static parameterless constructor can be declared for each class. This constructor will be called before any instance of the class is created or static function is called. You can achieve the same effect in C++, and I have done this quite a lot in my projects, but to have the support in the language makes it much cleaner.
A class can be specified as 'sealed' and this prevents all other classes from inheriting from it. Again, you could achieve the same effect in C++ but to have direct language support makes things much cleaner.
Now for the things I do not like about C#.
1) Everyting has to be in a class, there can be no 'free' functions. Unless you have done extensive generic programming using templates and the STL you may have no idea why I think this is such a bad idea.
2) No implicit cast from int to bool. This one really sticks in my craw. In standard C programming if (strlen(s)) {...}
is perfectly valid code, that is, the body of the if statement will only be executed if 's' is not the empty string. This type of code would not compile in C# because the return value of strlen() is not a bool. Yuk. It really feels like the language designer took some liberties to try to enforce their own coding style on the rest of the world.
3) Lack of templates. No modern general purpose language should be without them. It does look like they will eventually be added into C#.