OK, OK, so C# 3.0 is only just out of the door. As anyone who has been reading my stuff for a while will have realized, I like what they've done with the language. Here at PH, we have now fully migrated all our solutions to Visual Studio 2008, and can now use C# 3.0 language and .Net 3.5 framework features everywhere they're useful. This makes me happy (though some annoying issues migrating to Web Deployment Projects 2008 decidedly aren't making me happy).
I haven't thought long and hard about what I'd really like in C# 4.0. I think I need C# 3.0 to settle in a bit more. I've used it quite a bit, but it takes a while to fully realize the power of all that is there, and I certainly don't want to start suggesting additions to the language when there is already a perfectly good solution to that problem...
This morning I started working on a new library for a new feature we'll be rolling out in the not too distant future. It is the first production code that we're developing at PH using Visual Studio 2008, which brings us C# 3.0 and Linq.
Just one morning into it, it already feels like a vast improvement. It took all of ten minutes to get the DLinq classes generated in Visual Studio; it would have taken under five if it hadn't been my first time doing it and working it out as I went. Then they were ready to use, which was also trivial. No more writing SQL or stored procedures or calling methods on a data reader to get the data out: just instantiate the DataContext (which represents the database), write the query, and it's done...
Posted on Wednesday, November 28, 2007 at 6:25 AM
So I wanted to do:
private TTo Identity<TFrom,TTo>(TFrom I)
{
return (TTo)I;
}
Well, actually I didn't. I wanted C# to be smart enough to realize that if S is a subtype of T then List<S> can safely be assumed to be a subtype of List<T>. But anyway, that's not the case, and you have to call ConvertAll on the List to get it to be a List<T> rather than a List<S>. Joy. Anyway, turns out the above fails to compile. Thankfully, this works:
private TTo Identity<TFrom,TTo>(TFrom I)
{
return (TTo)(object)I;
}
But, argh.