>
>Can I ask you about the use of the Var type there? I know that was a new feature in C# 3.0 but thought it was for occasions when the type is unknown at compile time. Given your expertise I am sure there is a good reason.
No, it's just a shortcut to tell the compiler to infer the type based on the method you are calling. It's still strongly-typed and known at compile time. One of the things I thought was really dumb when I started using .NET was how redundant statements like this were:
StringBuilder sb = new StringBuilder();
You mean the variable is a StringBuilder - nah, no kidding?! Apparently other people thought this was silly as well and they gave us var - the compiler infers the type based on the type being created or returned by a method. OK, so they didn't give it to us for that reason, it was needed for anonymous types. But it's still a welcome addition.
This is equivalent:
var sb = new StringBuilder();
If you don't know the type at compile time then you would use the new "dynamic" type.