What’s the difference? Trenchcoat vs Duster

Today, yet another episode in my ongoing series “What’s the difference?” This time, a non-computer-related topic. I am often complimented on my choice of outerwear in the Seattle rainy season, and I hate to respond to a well-meant compliment with a correction. So I usually let all those “Nice trenchcoat!” comments slide and just say…


What’s the difference? Remainder vs Modulus

Today, another episode of my ongoing series “What’s the difference?” Today, what’s the difference between a remainder and a modulus, and which, if either, does the % operator represent in C#? A powerful idea that you see come up in mathematics and computer programming over and over again is the idea of an equivalence relation….


What’s the difference between a destructor and a finalizer?

Today, another dialogue, and another episode of my ongoing series “what’s the difference?” What’s the difference, if any, between a “destructor” and a “finalizer”? Both are mechanisms for cleaning up a resource when it is no longer in use. When I was asked this, at first I didn’t think there was a difference. But some…


What’s the difference between covariance and assignment compatibility?

I’ve written a lot about this already, but I think one particular point bears repeating. As we’re getting closer to shipping C# 4.0, I’m seeing a lot of documents, blogs, and so on, attempting to explain what “covariant” means. This is a tricky word to define in a way that is actually meaningful to people…


What’s the difference between "as" and "cast" operators?

Most people will tell you that the difference between “(Alpha) bravo” and “bravo as Alpha” is that the former throws an exception if the conversion fails, whereas the latter returns null. Though this is correct, and this is the most obvious difference, it’s not the only difference. There are pitfalls to watch out for here….


What’s the difference between a partial method and a partial class?

Like “fixed” and “into”, “partial” is also used in two confusingly similar-yet-different ways in C#. The purpose of a partial class is to allow you to textually break up a class declaration into multiple parts, usually parts found in separate files. The motivation for this feature was machine-generated code that is to be extended by…


What’s the difference between conditional compilation and the conditional attribute?

User: Why does this program not compile correctly in the release build? class Program { #if DEBUG     static int testCounter = 0; #endif     static void Main(string[] args)     {         SomeTestMethod(testCounter++);     }     [Conditional(“DEBUG”)]     static void SomeTestMethod(int t) { } } Eric: This fails to compile in the retail build because testCounter cannot…


What’s the Difference, Part Four: into vs into

The keyword “into” in a query comprehension means two different things, depending on whether it follows a join or select/group. If it follows a join, it turns a join into a group join. If it follows a select or group then it introduces a query continuation. These two features are quite different, but easily confused….


What’s the Difference? Part Three: fixed vs. fixed

I got an email the other day that began: I have a question about fixed sized buffers in C#:  unsafe struct FixedBuffer { public fixed int buffer[100]; } Now by declaring buffer as fixed it is not movable… And my heart sank. This is one of those deeply unfortunate times when subtle choices made in the…


What’s The Difference, Part Two: Scope vs Declaration Space vs Lifetime

“Scope” has got to be one of the most confusing words in all of programming language design. People seem to use it casually to mean whatever is convenient at the time; I most often see it confused with lifetime and declaration space. As in “the memory will be released when the variable goes out of…