|
-
Apr 3rd, 2006, 04:14 PM
#1
Thread Starter
Hyperactive Member
diff between me.control and _control ??
what is the difference between using me.controlname and _controlname?
-
Apr 3rd, 2006, 05:58 PM
#2
Re: diff between me.control and _control ??
Nothing at all. Just like there is no difference between these two statements:
VB Code:
Dim MyPoint1 As System.Drawing.Point
Dim MyPoint2 As Point ' Assuming you have System.Drawing imported
The fully qualified name is usually better because it makes things easier to read and understand. It is good coding practice to include it.
-
Apr 3rd, 2006, 08:25 PM
#3
Re: diff between me.control and _control ??
The underscore is used to indicate that a variable is a class member as opposed to a local variable. Personally, I generally don't use it for the same reasons that I don't use Hungarian notation. It just isn't needed in the modern IDE. The one time I do use it is if I am exposing a variable through a property. It allows you to give the variable and property basically the same name, e.g.:
VB Code:
Private _someVar As String
Public Property SomeVar() As String
Get
Return Me._someVar
End Get
Set
Me._someVar = Value
End Set
End Property
Using Me also identifies a variable as being a member but that's not why I use it. I use it to get Intellisense. In the example above, if I didn't use Me I would have had to type "_someVar". Because I used Me I would only have to type "me._" and Intellsense would show me the variable. The Intellisense in C# 2005 is smart enough to give you help from the first letter you type, making use of "this" unnecessary, but all other versions (VB and C#) don't.
-
Apr 3rd, 2006, 08:28 PM
#4
Re: diff between me.control and _control ??
Ctrl-Space invokes Intellisense immediately. If you've typed some chars already, it uses what's typed as a starting point.... if you haven't, then you get the intellisense with everything in it.
-tg
-
Apr 3rd, 2006, 09:31 PM
#5
Re: diff between me.control and _control ??
 Originally Posted by techgnome
Ctrl-Space invokes Intellisense immediately. If you've typed some chars already, it uses what's typed as a starting point.... if you haven't, then you get the intellisense with everything in it.
-tg
Now that I didn't know. You is da gnome dat knows.
-
Apr 4th, 2006, 09:00 AM
#6
Re: diff between me.control and _control ??
Not only that but it works in VB6 VS2002/2003/2005 .... and probably earlier versions of VS too.
-tg
-
Apr 4th, 2006, 09:12 AM
#7
Addicted Member
Re: diff between me.control and _control ??
Isn't is easier to type "me." and then select the variable name you are looking for that type it's name? I always use me.variableName, although the code looks annoying sometimes because of this...
-
Apr 4th, 2006, 10:31 PM
#8
Re: diff between me.control and _control ??
 Originally Posted by jmcilhinney
Now that I didn't know. You is da gnome dat knows. 
I thought I might mention that Ctrl+J will give you a list of all possible variables/properties/methods/etc no matter where your cursor is in the code. Ctrl+Space does the same thing, except it also attempts to make a prediction based on what you already have typed in, and will fill it in for you if it finds only one possible match.
Also, Ctrl+I will give you infromation about the current variable. Such as wether its data type.
Last edited by eyeRmonkey; Apr 4th, 2006 at 10:36 PM.
-
Apr 4th, 2006, 10:35 PM
#9
Re: diff between me.control and _control ??
Now that I didn't know. You is da mon-kay dat knows.
-tg
-
Apr 4th, 2006, 10:39 PM
#10
Re: diff between me.control and _control ??
 Originally Posted by techgnome
Now that I didn't know. You is da mon-kay dat knows.
-tg
Seems to me that it might be beneficial for me to make a list of keyboard shortcuts. But, unlike my VB6 to .NET equivalent chart, the shortcuts are probably possible to find online.
-
Apr 4th, 2006, 11:14 PM
#11
Re: diff between me.control and _control ??
W.R.T. the first post, Me.controlname and _controlname are two different variables so there's a lot of difference in fact 
As John said, the underscore prefix is just a notation, used to indicate a private member variable.
You don't want to get too carried away with underscores as in many contexts anything more than a single underscore prefix denotes an indentifier as being reserved for the compiler.
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
|