Friday, May 06, 2005

Back with (dot)NET

After working with the .NET framework since beta 1 I recently took a 8 month hiatus from it to do some work with linux and python/perl. Over the last couple days I dug back into it using v2.0 of the framework and Visual C# Express 2005. I have to say WOW. Microsoft really was able to pull off some great things.

Before the hiatus a few upcoming features were interesting to me. Generics and Annonymous methods are two very useful framework features that I never got to see until now.

With generics, something I've been dying to use, we can instantiate a class with specific types. For example let's create a class that holds a reference to a type that we'll define:


public class HoldSomething<anytype>
{
private anytype _data;

public void Store(anytype data)
{
_data = data;
}

public anytype Retrieve()
{
return _data;
}
}

It's an overly simple example but with that class we can instantiate it with the type we're going to use:

// let's work with an int
HoldSomething<int> hold = new HoldSomething<int>();
hold.Store(10);

// let's work with a string
HoldSomething<string> holdastring = new HoldSomething<string>();
hold.Store("Hello World");

I believe Generics makes the C# language a bit more dynamic, kind of like Python or Perl. There were many times in that past where I had to reference and unknown type with System.Object resulting in implicit boxing.

I'm also blown away with all the neat little features tucked in Visual C# 2005: refactoring support, practical debugging enhancements, a light footprint, better ergonomics, and more as I keep using it.

3 Comments:

At 9:55 AM , Blogger Aymiee said...

Wow.. c# being a type-safe language, I dreaded working with collections and having to deal with casting it to the correct type. Interesting read, I will have to do more reading up on this...

 
At 2:23 PM , Anonymous Anonymous said...

Your less-than and greater-than symbols aren't being translated into HTML, so the type given to the ctor of HoldSomething is invisible in Firefox.

 
At 3:19 PM , Blogger Richard said...

WHOW...Good catch!

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home