Toxic Elephant

Don't bury it in your back yard!

New Language Features in .NET

Posted by matijs 06/09/2006 at 16h36

One of the reasons I have a dislike for both Java and the main .NET langauges, VB.NET and C#, is the ridiculous verbosity involved in creating and filling an object variable. Typically, what you get is something like:

Some.Deep.Namespace.Structure.SomeClass foo = new Some.Deep.Namespace.Structure.SomeClass();

The repitition of the class name makes the horrid namespace nesting twice as bad. And no, this is not about typing, this most definitely is about reading.

So, you can imagine my pleasant suprise when, belatedly, I came across a discussion of var. Basically, var is a new keyword in the upcoming C# 3.0 that allows you to do this:

var foo = new Some.Deep.Namespace.Structure.SomeClass();

And then, and this is the good part, the C# compiler will infer that foo is a variable of type Some.[..].SomeClass and will complain if you try to store anything else in it1.

Same type safety with half the reading. Excellent.

Now, that’s not all. It turns out there’s a lot more interesting stuff coming in C# 3.0, making it more concise and powerful.

1 Yes, I’m aware that ML does this and even more.

Tags no comments no trackbacks

Comments

Comments are disabled