Using Reserved Words as Identifiers in VB.NET by Theo Gray
I came across a problem at work the other day when the plugin that I was using, jQuery file uploader, required specific properties to be returned to it from the VB.NET object deserialisation when an error occurred. One of these properties was Error
, which is a reserved language keyword in VB.NET. Ordinarily I would never be using reserved words as identifiers in VB.NET, since you can’t anyway because the compiler doesn’t allow it and it’s usually a very bad idea. But in this case it was either use a reserved keyword or have to modify the plugin source which I wasn’t too keen on doing.
I came across this article by Theo Gray that outlined that it was as simple as surrounding the property in square brackets []
, much in the same way you can use reserved keywords as column names in MSSQL. This worked great and it was a perfectly simple solution to my problem, but I certainly won’t be making a habit of it!