Stupid .NET Tricks #10

1:06 pm programming

Some .NET classes (System.Data.DataSet is the one I’m currently using) define a property called “Namespace”. In VB, “Namespace” (note the capital “N”) is a reserved word used to associate a class with a particular namespace. Since it’s a reserved word, it’s not a valid identifier in VB… meaning that the MS classes that contain the property “Namespace” were not written in VB (at least without some sort of compiler hack).

Currently I’m trying to reimplement a (legacy) class that subclasses DataSet; I want to break the DataSet inheritance and replace it with custom members. Due to the “Namespace” conflict, I can’t do this in VB, although it wouldn’t be a problem in C#, and isn’t a problem for all of the other properties in the old class.

So much for language independence.

Update: I spoke too soon; VB does have a mechanism for specifying identifier names that match keywords: just enclose the identifier in brackets. It’s unfortunate that it’s necessary, but it’s easy enough to implement once you know the trick.

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.