views:

362

answers:

3

I'm creating a car class. Make and model are properties but both make and model appear to be reserved words in C#. What's the best practice for naming properties/methods when your preferred name is a reserved word?

My first instinct is to call the properties CarMake, CarModel (so a convention of ClassNamePropertyName). Is there some better convention or is this the best approach?

EDIT>> My mistake, make and model aren't actually reserved words. VS intelliesense and code coloring made it appear so to me at first glance. Though my question does stand for future reference.

Thanks!

+2  A: 

In VB.NET, you can enclose the property name within square brackets:

Public Property [Make] As String

(I'm not sure about C#, but you also tagged the post as vb.net)

HardCode
+1  A: 

Neither make nor model are reserved C# words. In the case that you do need to use a reserved word, the best thing to do is to try to come up with a synonym.

Andrew Hare
Visual Studio has intellisense for both make and model as though they're reserved words. Actually, it appears they're part of the BCL. Is that correct?
Cory House
+6  A: 

I usually try to think of some synonymous alternative word, or variation, though it doesn't sound like that is applicable for you.

Alternatively, you can use the '@' prefix (in C#) or [square braces] (in VB.NET) to explicitly avoid the conflict with reserved words in the language.

Daniel Fortunov