After this evening's Northwest Ohio .NET User Group meeting, Jason Follas and I met up at Tony Packo's for a bit of post-meeting hangtime. In our conversation, Jason admitted his frustration at not being able to write code like this using C# generics:
Unfortunately, that code doesn't compile. The problem is that List<> has to have its "T" type parameter filled in. To solve this dilemma, make "DoSomethingWithList" a generic method like this:
Now, the list parameter will be of type List<T> where T is filled in when the DoSomethingWithList method is called. Hence, we can write code like this:
IMO, the calling code isn't very elegant with the angle brackets added to DoSomethingWithList. Fortunately, the C# compiler will infer the actual types of generic type parameters if you don't fill them in. I'm currently working on an article that explores this feature in detail because I don't see many people using it and, frankly, it is a life saver for cleaning unwanted angle-brackets out of perfectly readable code. Here is the code again using compiler inference:
Page rendered at Wednesday, February 08, 2012 9:20:16 AM (Pacific Standard Time, UTC-08:00)
If feel a bit behind and need to catch up on WPF, this is the book.
Great book on F# containing from Beginner to Advanced. It even has chapters on more arcane features of the language, such as Computation Expressions and Quotations.
Because this book provides source code in Standard ML, it's a fantastic resource for learning F#. One bit of warning: this book does not teach classic data structures. While structures such as binomial heaps and red-black trees are presented, it is assumed that the reader already knows and understands them.
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.