How do we ensure that method type inference terminates?

I missed the party. I was all set to be on that massive wave of announcements about TypeScript, and then a family emergency kept me away from computers from Thursday of last week until just now, and I did not get my article in the queue. Suffice to say that I am SUPER EXCITED about…

8

He’s So Dreamy

Happy New Year all! It has just been brought to my attention that this blog and the Programmer Ryan Gosling photo blog share at least one reader: I admit it, I LOL’d. In the interests of total accuracy I’d like to point out that the first entry on the blog contains a subtle error: .NET…

5

Curiouser and curiouser

Here’s a pattern you see all the time in C#: class Frob : IComparable<Frob> At first glance you might ask yourself why this is not a “circular” definition; after all, you’re not allowed to say “class Frob : Frob“(*). However, upon deeper reflection that makes perfect sense; a Frob is something that can be compared…

24

Exact rules for variance validity

I thought it might be interesting for you all to get a precise description of how exactly it is that we determine when it is legal to put “in” and “out” on a type parameter declaration in C# 4. I’m doing this here because (1) it’s of general interest, and (2) our attempt to make…

17

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…

23

Some new videos

Somehow it has happened again; people just keep on recording videos of me and putting them on the internet. In these videos you find out what I look like when lit from above and behind. Kinda spooky. We should have made the room entirely dark and held a flashlight underneath my face. That would be,…

6

Why is covariance of value-typed arrays inconsistent?

Another interesting question from StackOverflow: uint[] foo = new uint[10];object bar = foo;Console.WriteLine(“{0} {1} {2} {3}”,          foo is uint[], // True  foo is int[],  // False  bar is uint[], // True  bar is int[]); // True What the heck is going on here? This program fragment illustrates an interesting and unfortunate inconsistency between the CLI type system and…

22

Why do ref and out parameters not allow type variation?

Here’s a good question from StackOverflow: If you have a method that takes an “X” then you have to pass an expression of type X or something convertible to X. Say, an expression of a type derived from X. But if you have a method that takes a “ref X”, you have to pass a…

19

The void is invariant

[UPDATES below]  A while back I described a kind of variance that we’ve supported since C# 2.0. When assigning a method group to a delegate type, such that both the selected method and the delegate target agree that their return type is a reference type, then the conversion is allowed to be covariant. That is,…

21

Representation and Identity

(Note: not to be confused with Inheritance and Representation.) I get a fair number of questions about the C# cast operator. The most frequent question I get is: short sss = 123;object ooo = sss;            // Box the short.int iii = (int) sss;         // Perfectly legal.int jjj = (int) (short) ooo; // Perfectly legalint kkk…

26