November 30, 2010

C# Generics

A few days ago I was reviewing some old code that I had written a while back, and I found that I was having problems scanning the code quickly to see what it was supposed to do. After a couple a minutes, I realized that a number of areas in the code we're a little more verbose and confusing than they needed to be. The primary reason behind this: no generics. I know generics have been around for a while, and I have just gotten used to having them around. They make it much easier to deal with collections of objects in a type safe, and easy to follow manner.

Sure, before generics you could make things work, but in many cases I found myself having to cast object to a type, that I knew they we're. Now with generics, I just don't even worry about it. Everything just works, and that's good.

No comments: