473,657 Members | 2,993 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

private variable vs. actual property in a class module?

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.Sav e (_loginName) or LoginObject.Sav e (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.LoginObjec t
'****** what is the difference in these 2 lines? *******
LoginObject.Sav e (_loginName)
LoginObject.Sav e (me.LoginName)
'************** *************** *************
end function

End Class
Thank You,

SteveS
Jul 21 '05 #1
1 1689
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
"SteveS" <ss*****@trendm ls.com> wrote in message
news:eu******** ******@TK2MSFTN GP09.phx.gbl...
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.Sav e (_loginName) or LoginObject.Sav e (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.LoginObjec t
'****** what is the difference in these 2 lines? *******
LoginObject.Sav e (_loginName)
LoginObject.Sav e (me.LoginName)
'************** *************** *************
end function

End Class
Thank You,

SteveS

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
3798
by: gabor | last post by:
hi, as far as i know in python there aren't any private (i mean not accessible from the outside of the object) methods/fields. why? in java/c++ i can make a method private, this way unaccessible for the outside world. i think it helps a lot to make for example a library more robust.
21
4400
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So if "global variables get re-set" doesn't tell the whole story, then what does? ***please note*** I'm not looking for a solution - I'm looking for a more detailed description of what happens when an un-handled error occurs - possibly with help file...
2
1509
by: Bob | last post by:
Is this a bug? Expected behavior? Did I get the binding flags wrong? Bob -------------------- Imports System.Reflection Module Main
7
1073
by: Just Me | last post by:
I have a project that contains a usercontrol, some forms and a module. The only thing in the module is one variable that is there so that it can be used by the control and all the forms. Couldn't I put the variable in the usercontrol and somehow set it so that it can be used by usercontrol and all the forms? If so, how?
2
1611
by: dumbo | last post by:
Hello, who gives one more shining solution to me? My application load form "A". The form "A" by means of a push-button load form "B" that in its turn by means of a push-button load form "C". Form "B" contains one variable "Private" "VarB". How I can read the value of "VarB" from form "C"? All the form come loaded with the following brace of instructions: Sub Button2_Click(ByVal sender As System.Object, ByVal and As System.EventArgs)...
1
357
by: SteveS | last post by:
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
11
5636
by: prefersgolfing | last post by:
I'm trying to find on MSDN, or someplace, that speaks to variables being public or private by default. Anyone know where? Thanks.
7
5067
by: Victor | last post by:
I just tried a test comparing a Function to a Private Function with this code: <% Option Explicit dim X1 X1 = 9 Private Function RealTest(here) RealTest = here + X1 End Function
17
30622
by: Peng Yu | last post by:
Hi, I'm wondering if there is something in namespace like the 'private' keyword in class? I want to define some class or function that can only be used within that namespace. Thanks, Peng
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.