TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

.NET Framework 2.0 - So Far So Good

It's been close to a month since "the RTM" and I'm starting to get a good feel for what new features of the .NET Framework are becoming really useful tools for the ol' dev toolbox. First and foremost are generics. I don't mean custom generic classes, I mean the System.Collections.Generic and ObjectModel namespaces. More specifically, List<T> and Dictionary<K,V>. Collection<T> and KeyedCollection<K,V> are great for base classes, but I find myself using List<T> and Dictionary<K,V> a lot in lieu of ArrayList and Hashtable.

Nullable types are probably next on the list. I like being able to use a value type, check to see if it is null, and handle as appropriate, such as the following code you might see in ASP.NET 2.0.

bool? b = (bool?) ViewState["Required"];
return b ?? false;

Something that I thought I would absolutely hate to see in code, but I'm now finding to be quite handy is anonymous methods. The Sort, Find, and ConvertAll methods of List<T> for example. Using ConvertAll, I can easily create a list of object property values in a collection. Since the generic list knows what type it contains, I can call ToArray() as well to get a strongly typed array of the property values.

public void Save(List<FormDesignerControl> controls) {
   
List<string> names = controls.ConvertAll(delegate(FormDesignerControl c) { return c.Name; });
    filter.PredicateExpression.Add(new FieldCompareRangePredicate(ControlFields.ControlName, null, names.ToArray()));
}

It will be interesting to see how things are looking in a few more months.


Digg!

posted on Friday, December 02, 2005 11:32 AM

Feedback

No comments posted yet.