Most unintuitive behaviour in the .Net framework?
- by BlueRaja
Intended behavior is often another phrase for bug-which-we-knew-about-when-we-wrote-it, but-we-wrote-it-anyways. Because it was "intended" (or perhaps it is now too late or too difficult), many of these extremely-unintuitive bugs never get fixed.
For instance, consider the following code (C#):
TextInfo textInfo = Thread.CurrentThread.CurrentCulture.TextInfo;
textInfo.ToTitleCase("hello world!"); //Returns "Hello World!"
textInfo.ToTitleCase("hElLo WoRld!"); //Returns "Hello World!"
textInfo.ToTitleCase("Hello World!"); //Returns "Hello World!"
What would you expect textInfo.ToTitleCase("HELLO WORLD!"); to return? In fact, it returns "HELLO WORLD!". This was well-documented "intended behavior," but, in my eyes, is extremely unintuitive, and therefore a bug.
What is some other unintuitive behavior like this in this in the .Net framework? Bonus points if you can provide a fix that does not break backwards-compatibility.
Remember! Always keep these two simple rules in mind when designing an API (or anything else):
Make the common case the default, and Keep It Simple, Stupid!