VB.NET developers – Please don’t name your properties the same as your classes

Today I was reminded that C# is a bit more strict in its naming conventions than VB.NET. After I converted an old project from VB.NET to C#, I spent a good part of the afternoon updating the names of properties that had been called the same as the class, which is obviously not allowed in C#. However, do we really need properties with the same name as the class? Maybe that’s a code smell?

Suggestion: Instead of making classes like this:

Public Class PhoneNumber
    Public String Prefix
    Public String PhoneNumber
End Class

Make them like this:

Public Class PhoneNumber
    Public String Prefix
    Public String Number
End Class

Then you can convert them to C# using any old tool for this (e.g. SharpDevelop), without having to haunt your source code looking for references to the now no-longer-valid property PhoneNumber.PhoneNumber.

Advertisements
This entry was posted in .NET, C#, VB. Bookmark the permalink.

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