.NET Discussion

.NET Issues, Problems, Code Samples, and Fixes

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?

Advertisements

December 13, 2007 - Posted by | ASP.NET, Tips & Tricks

2 Comments »

  1. 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!

    Comment by Josh Stodola | December 31, 2007 | Reply

  2. 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.

    Comment by Some.Net(Guy) | December 31, 2007 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: