Dynamic contagion, part two

Last time I discussed how “dynamic” tends to spread through a program like a virus: if an expression of dynamic type “touches” another expression then that other expression often also becomes of dynamic type. Today I want to describe one of the least well understood aspects of method type inference, which also uses a contagion…

2

Dynamic contagion, part one

Suppose you’re an epidemiologist modeling the potential spread of a highly infectious disease. The straightforward way to model such a series of unfortunate events is to assume that the population can be divided into three sets: the definitely infected, the definitely healthy, and the possibly infected. If a member of the healthy population encounters a…

9

A method group of one

I’m implementing the semantic analysis of dynamic expressions in Roslyn this week, so I’m fielding a lot of questions within the team on the design of the dynamic feature of C# 4. A question I get fairly frequently in this space is as follows: public class Alpha{  public int Foo(string x) { … }}…dynamic d…

8

An "is" operator puzzle, part two

As I said last time, that was a pretty easy puzzle: either FooBar, or the type of local variable x, can be a type parameter. That is: void M<FooBar>(){  int x = 0;  bool b = x is FooBar;  // legal, true if FooBar is int.  FooBar fb = (FooBar)x; // illegal} or struct FooBar…

13

Breaking changes and named arguments

Before I get into the subject of today’s post, thanks so much to all of you who have given us great feedback on the Roslyn CTP. Please keep it coming. I’m definitely going to do some articles on Roslyn in the future; the past few weeks I have been too busy actually implementing it to…

29

Optional argument corner cases, part four

(This is the fourth and final part of a series on the corner cases of optional arguments in C# 4; part three is here.) Last time we discussed how some people think that an optional argument generates a bunch of overloads that call each other. People also sometimes incorrectly think that void M(string format, bool…

18

Optional argument corner cases, part three

(This is part three of a series on the corner cases of optional arguments in C# 4; part two is here. Part four is here.) A lot of people seem to think that this: void M(string x, bool y = false) { … whatever … } is actually a syntactic sugar for the way you…

6

Optional argument corner cases, part two

(This is part two of a series on the corner cases of optional arguments in C# 4. Part one is here. Part three is here. This portion of the series was inspired by this StackOverflow question.) Last time we saw that the declared optional arguments of an interface method need not be optional arguments of…

11

Optional argument corner cases, part one

(This is part one of a series on the corner cases of optional arguments in C# 4. Part two is here.) In C# 4.0 we added “optional arguments”; that is, you can state in the declaration of a method’s parameter that if certain arguments are omitted, then constants can be substituted for them: void M(int…

10

So many interfaces!

Today, another question from StackOverflow, and again, presented as a dialogue as is my wont. The MSDN documentation for List<T> says that the class is declared as public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>,                        IList, ICollection, IEnumerable Does List<T> really implement all those interfaces? Yes. Why so many interfaces? Because when an interface like…

29