private variable vs. actual property in a class module?

S

SteveS

What's the difference in using the private variable as opposed to the actual
property in a class module? Which is better or more efficient? (
LoginObject.Save (_loginName) or LoginObject.Save (me.LoginName)

FOR EXAMPLE:

Class MyClass

Private _loginName As String
Public Property LoginName() As String
Get
Return _loginName
End Get
Set(ByVal Value As String)
_loginName = Value.ToLower()
End Set
End Property

public sub Save()
dim LoginObject as new Data.LoginObject
'****** what is the difference in these 2 lines? *******
LoginObject.Save (_loginName)
LoginObject.Save (me.LoginName)
'******************************************
end function

End Class


Thank You,

SteveS
 
J

Jan Tielens

I don't think it makes any difference the JIT will optimize the Me.LoginName
so there won't be any performance difference.

In my opinion using the property (Me.LoginName) is advisable, because in
that case you're using OO encapsulation.

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top