Best practice for renaming property / method names that are reserved words?

I am creating a class. What is the best practice for naming properties / methods when your preferred name is a reserved word?

+6
c # naming-conventions
source share
3 answers

I usually try to think of some kind of synonym for an alternative word or variation, although this does not seem to apply to you.

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

+11
source share

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

Public Property [Make] As String 

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

+2
source share

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

+1
source share

All Articles