Fabrice's weblog
Tools and Source
-
Correct exception handling
If you look at this post by SantoshZ of the C# team, you'll see code like this:
-
Watch Anders Hejlsberg talk about C#
-
"The C# compiler won't let me do it" - answer
Drew knows his thing. He was the one who gave the right explaination for my quiz. I just copy it here:
DictionaryEntry is a structure and you're foreaching which means the instance is coming from IDictionaryEnumerator.Current therefore assigning to only the local copy. This would be a nasty problem if people forgot about the semantics of value types vs. ref. types, so the C# compiler prevents you from doing this.
However, I agree with Eric Newton that the message from the compiler should be clearer! The current one is very confusing.
Now, if you want something even more confusing, you can try the following code:
IDictionary dictionary = new Hashtable();
dictionary["dummy"] = "dumb";
IEnumerator enumerator = dictionary.GetEnumerator();
while (enumerator.MoveNext())
{
DictionaryEntry entry;
entry = (DictionaryEntry) enumerator.Current;
entry.Value = 0; // no compiler error, but "error" nonetheless
}
Console.WriteLine(dictionary["dummy"]);
This one compiles, but doesn't do what you'd expect at first. Guess what the output will be... So yes, the compiler message is useful (even if not easy to understand), but doesn't fire in all the cases...
-
"Comments on this post are closed"
I would like to apologize to readers: you'll notice that posting comments on most of the posts of this weblog is currently disabled. You'll see "Comments on this post are closed" instead. I'm sorry about this, and I can't change anything about it right now :-( This is a new site-wide (weblogs.asp.net) setting.
I hope we'll be able to reactivate the comments soon! I don't like that setting at all. I appreciate comments much, and I do not consider that previous posts as obsolete.
Scott, please do something! I you want this feature to be disabled too, please say it.
-
"The C# compiler won't let me do it"
In the spirit of language quizes, you can try to find why the following code does not compile:
-
Nested comment blocks in C#
In C#, we can use two kinds of delimiters to comment code: // and /*...*/
The first one applies to one line, the second can be applied to a set of lines or just a part of a line (block commenting). These two possibilities are useful, but I always missed the ability to nest comment blocks. -
Tools built for Mono
I added a new attribute to the SharpToolbox: [BuiltForMono].
-
Events, references, garbage collecting, memory leaks and weak delegates
I was playing with services and containers, as part of my implementation of Inversion of Control. All was fine until events came into play.
I needed to connect two services through events. Oh, all was working fine: there were no apparent troubles. But under the too calm surface sneaked a dreadful memory leak. Events don't play well with a loosely coupled environment by default. Better be warned. -
Let .NET 2.0 Go Live
Dear Microsoft, we really need a date for .NET 2.0's "Go Live" license (and consequentely the beta 2). We need to know right now whether we should start developing with .NET 2.0 or whether it's too soon because we won't be allowed to deploy in production before next year or so.
-
Objects and Services
Clemens Vasters' post "Rows and Columns + Elements and Attributes is all you need" initiated an interesting discussion about the place of objects in SOA.