ASP.NET: How To Name A Variable Or Property Using .NET’s “Reserved” Words
Let’s say you want to give your class a boolean property named Error that gets turned on or off if something goes awry in your code. You would think that you can’t do this because the word “Error” is reserved by .NET. However, there is a way. All you have to do is put square brackets around the word! For instance:
Public Property [Error]() As Boolean
Easy, no?
RSS Feed
I spent like an hour last year trying to figure out how to get a variable (A constant, actually) named “DO” to behave. “DO” is a prefix identifier we were using, so I wanted stored it in our Constants class. I knew it had to be possible; how could MS forget something like that?!
I did end up finding this exact solution, but sheesh, I wasted a whole hour!
Yeah, occasionally I’ll find myself searching for the solution to the tiniest little problem, sometimes as dumb as “is it possible to even do ____”, for an hour or two before I either find the answer or give up and figure out a workaround. Even on something as little as this, where instead of naming a variable “Error”, I could call it “HasErrors” or ANYTHING else…haha.
Yeah, man, I know the feeling, and I don’t think we’re alone.