|
-
Feb 23rd, 2018, 07:49 PM
#8
Re: Should I add "Me" to my controls
I would suggest that the most important thing is to be consistent in whatever you do. Inconsistency can lead to confusion, because if someone reading your code (including you, some time after writing it) may well think that two pieces of code do different things if they are written it two different ways.
I used to use Me in VB and 'this' in C# all the time. I now don't use them at all unless it's required. The most common situation where it's needed is when you have a constructor parameter that is used to set a field/property of the same name, e.g.
vb.net Code:
Public Property Name As String Public Sub New(name As String) Me.Name = name End Sub
In such cases, I would say that it is desirable to use the same name for the parameter as the property, because it makes it plain to the caller what the value represents. As suggested, the disambiguation is not required in C# but I would still tend to use 'this' there too, because it's too easy to either miss that identifiers are different only by the case of their first letter, or it's too easy to use the wrong one in code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|