Why is my T-SQL behaving this way? Is this standard SQL behaviour? Can you think of a good solution, assuming you need your string equalities to be strictly correct?
The SQL 92 spec requires a comparison of two strings of unequal length to append trailing spaces to the shorter string until they are the same length, and then make the comparison between the now-equal-length strings. What this means is that if the longer of the two strings has trailing spaces but everything before the trailing spaces is a match then the strings will compare equal.
I found this excellent blog post by Anthony Bloesch which goes over the various ways you can work around this, assuming that the trailing spaces in your strings are meaningful and you need a proper comparison. Also note that any of these approaches will kill your indexing performance.
.NET Daily Quiz #037
Try to do these without compiling. Which of these type definitions is not valid, and why?
Invalid type definitions are (with comments):
See the C# spec, section 10.1.5 — some of the rules around type parameter constraints are not necessarily obvious.
.NET Daily Quiz #038
In the following program, which DoThings overload is chosen by the compiler?
What happens if I change DoThings to this:
Can you explain this behaviour?
It’s a trick question. This program exploits a bug in the C# compiler. In the first program will select DoThings(params string args) while the second program will fail to compile due to an ambiguous invocation. The bug is that both programs are ambiguous and the first program should fail to compile. For a really interesting and detailed analysis of this overload resolution problem take a look at this excellent StackOverflow answer by Eric Lippert.
.NET Daily Quiz #039
I want consumers of my class to be able to do this:
Show me how to write Foo without extending a class that currently supports this kind of initializer syntax.
We need to implement IEnumerable (why? I don't know. The spec never explains this point and there's no mechanical reason for it I can see) and a method named Add which accepts a single argument (return type not important, apparently). Totally awesomely, the Add method does not need to come from an interface.
Any overload of Add will allow you to add that type to your collection constructor syntax. Normal overload resolution rules apply to Add.
.NET Daily Quiz #040
My application crashes at runtime. Why? What important design consideration (C#-specific) am I violating?
_foo is null and _foo.ToLower() throws an error as constructors execute from the base type up so _foo hasn't been initialized. If you use ReSharper is a similar tool no doubt you have seen the warnings about calling virtual methods from constructors, and this is why. For more detail check out this StackOverflow question, or read Eric Lipperts excellent blog articles on the topic of constructor and initializer call order, part I and part II.