Immutability in C# Part One: Kinds of Immutability

I said in an earlier post that I believe that immutable objects are the way of the future in C#. I stand by that statement while at the same time noting that it is at this point sufficiently vague as to be practically meaningless! “Immutable” means different things to different people; different kinds of immutability…


Covariance and Contravariance in C#, Part Ten: Dealing With Ambiguity

OK, I wasn’t quite done. One more variance post! Smart people: suppose we made IEnumerable<T> covariant in T. What should this program fragment do? class C : IEnumerable<Giraffe>, IEnumerable<Turtle> {    IEnumerator<Giraffe> IEnumerable<Giraffe>.GetEnumerator() {         yield return new Giraffe();    }    IEnumerator<Turtle> IEnumerable<Turtle>.GetEnumerator() {         yield return new Turtle();    }// [etc.]} class Program {    static void Main()  {       …


A Couple Links

Just two unrelated links today. First, Raymond’s post today reminded me of one of my favourite lines from the L.A. Story screenplay: “Look, rather than do an interview with me, which would be fascinating, by the way, because of my interesting word usements I structure, what if I showed you around town a little?” Pre-envisioning? What…


C# 3.0 Return Type Inference Does Not Work On Method Groups

UPDATE: A lot of people have linked to this article which is somewhat out of date now. This article describes why in C# 3.0, return type inference does not work when the argument is a method group and the formal parameter is a generic delegate. As you can see, there was a lot of feedback…


Covariance and Contravariance in C#, Part Nine: Breaking Changes

Today in the last entry in my ongoing saga of covariance and contravariance I’ll discuss what breaking changes adding this feature might cause. Simply adding variance awareness to the conversion rules should never cause any breaking change. However, the combination of adding variance to the conversion rules and making some types have variant parameters causes…