Monday, March 26, 2007

Using VB keywords as Variables

This is something I figured out awhile ago but haven't bothered to post it until now. Like I mentioned in an earlier post, I have started using VB.Net at work. As I was trying to convert some sample from C# to VB.Net, I ran into a problem. In C#, a name of a get/set accessor was not a keyword but in VB.Net it was. No matter what libraries or how many different online code converters I tried, I could not get it to work. I finally resorted to google and found out that you can surround a keyword with brackets ([ ]) and than you can use that keyword however you need. In my case it allowed me to use custom sinks in .NET Remoting. Here's an example:

Dim [New] as String
New = "Blah"

As a very BIG note: Be careful when using it. When you can name something other than a reserved keyword, do so. It can cause many issues if you use this unwisely.

1 comment:

Anonymous said...

Yes in C# you have to use @.