473,624 Members | 2,606 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class Properties

I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?

Example:

Public Class myClass
Private privateValues() as Long
'
' do other stuff to initialize everything here
'
Public ReadOnly Property getPrivateLongV alue_p(ByVal index as integer)
as Long
Get
return privateValues(i ndex)
End Get
End Property
' versus
Public Function getPrivateLong_ f(ByVal index as Integer) as Long
return privateValues(i ndex)
End Function
End Class

This may not be a good example of a reason to use one over the other, but
was interested to know what the differences are?
Nov 21 '05 #1
7 1226
as I understand it, property accessors are functions so go with what you
feel makes more logical sense for the user-devs.

-smith

"Dave" <dave@4_rem_ove _scotts.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?

Example:

Public Class myClass
Private privateValues() as Long
'
' do other stuff to initialize everything here
'
Public ReadOnly Property getPrivateLongV alue_p(ByVal index as integer)
as Long
Get
return privateValues(i ndex)
End Get
End Property
' versus
Public Function getPrivateLong_ f(ByVal index as Integer) as Long
return privateValues(i ndex)
End Function
End Class

This may not be a good example of a reason to use one over the other, but
was interested to know what the differences are?

Nov 21 '05 #2
as I understand it, property accessors are functions so go with what you
feel makes more logical sense for the user-devs.

-smith

"Dave" <dave@4_rem_ove _scotts.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?

Example:

Public Class myClass
Private privateValues() as Long
'
' do other stuff to initialize everything here
'
Public ReadOnly Property getPrivateLongV alue_p(ByVal index as integer)
as Long
Get
return privateValues(i ndex)
End Get
End Property
' versus
Public Function getPrivateLong_ f(ByVal index as Integer) as Long
return privateValues(i ndex)
End Function
End Class

This may not be a good example of a reason to use one over the other, but
was interested to know what the differences are?

Nov 21 '05 #3
"Dave" <dave@4_rem_ove _scotts.com> schrieb:
I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?


Classes represent entities.
Properties represent the entitiy's attributes.
Methods represent operations that can be performed by the entity.

So it's on the one hand a decision based on semantics. On the other hand,
the characeristics of the implementation should influence the decision.
Accessing a property should be "fast", there should not be long calculations
involved. Properties simply return the value of an attribute (sure, this
can include some calculation work or similar). Methods do some work before
returning in most cases.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
"Dave" <dave@4_rem_ove _scotts.com> schrieb:
I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?


Classes represent entities.
Properties represent the entitiy's attributes.
Methods represent operations that can be performed by the entity.

So it's on the one hand a decision based on semantics. On the other hand,
the characeristics of the implementation should influence the decision.
Accessing a property should be "fast", there should not be long calculations
involved. Properties simply return the value of an attribute (sure, this
can include some calculation work or similar). Methods do some work before
returning in most cases.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
There are a few differences that might prompt one to use a property instead
of a Method such as accessing class properties thru the PropertyDescrip tor
Collection Class in the case of accessing classes with different properties
in a routine that doesn't know before hand what class will be passed to it as
an object.

"Dave" wrote:
I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?

Example:

Public Class myClass
Private privateValues() as Long
'
' do other stuff to initialize everything here
'
Public ReadOnly Property getPrivateLongV alue_p(ByVal index as integer)
as Long
Get
return privateValues(i ndex)
End Get
End Property
' versus
Public Function getPrivateLong_ f(ByVal index as Integer) as Long
return privateValues(i ndex)
End Function
End Class

This may not be a good example of a reason to use one over the other, but
was interested to know what the differences are?

Nov 21 '05 #6
There are a few differences that might prompt one to use a property instead
of a Method such as accessing class properties thru the PropertyDescrip tor
Collection Class in the case of accessing classes with different properties
in a routine that doesn't know before hand what class will be passed to it as
an object.

"Dave" wrote:
I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?

Example:

Public Class myClass
Private privateValues() as Long
'
' do other stuff to initialize everything here
'
Public ReadOnly Property getPrivateLongV alue_p(ByVal index as integer)
as Long
Get
return privateValues(i ndex)
End Get
End Property
' versus
Public Function getPrivateLong_ f(ByVal index as Integer) as Long
return privateValues(i ndex)
End Function
End Class

This may not be a good example of a reason to use one over the other, but
was interested to know what the differences are?

Nov 21 '05 #7
Thanks to all who responded. Your explanations have helped me get a better
understanding and have been very helpful.

Dave
"Dave" <dave@4_rem_ove _scotts.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?

Example:

Public Class myClass
Private privateValues() as Long
'
' do other stuff to initialize everything here
'
Public ReadOnly Property getPrivateLongV alue_p(ByVal index as integer)
as Long
Get
return privateValues(i ndex)
End Get
End Property
' versus
Public Function getPrivateLong_ f(ByVal index as Integer) as Long
return privateValues(i ndex)
End Function
End Class

This may not be a good example of a reason to use one over the other, but
was interested to know what the differences are?

Nov 21 '05 #8

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

Similar topics

21
4063
by: Jon Slaughter | last post by:
I have a class that is basicaly duplicated throughout several files with only members names changing according to the class name yet with virtually the exact same coding going on. e.g. class A { std::vector<B*> Bs; public:
5
7280
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace properties.xsd this creates properties.cs
7
6612
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
6
2215
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base class would have CurrentUser property that would hold customer class in session and that was fine for all my situations. Now ASP.NET 2.0 came and we have Profile property for pages that could be extended with configuration to have custom...
16
1902
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I can get this using: dim b as string b = DirectCast(myarraylist(0),myclass).myproperty However, I want to use an object to define the type "MyClass" like: dim C as type = type.GetType(myarraylist(0))
9
2220
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that all have a different enumeration in them called Properties. I want to basically have a variable The_Class that I can dynamically point to either Class_A, Class_B, or Class_C and then do The_Class.properties to get the correct enumeration. How...
2
1460
by: mgoold2002 | last post by:
Hello. I've just begun programming in VB .NET, and I'm trying to turn all my modules into classes. In order to retrieve/exchange values from one class to another, I initiated New instances of the classes in each class where I needed to retrieve a property or method. I discovered that this reciprocal loading of class instances led to stackoverflow exceptions. I am now remedying this problem by sharing properties among the classes. I...
3
2041
by: Simon Hart | last post by:
Hi, I am trying to implement some functionality as seen in MS CRM 3.0 whereby a basic Xml is deserialized into an object which contains properties. What I want to do from here is; cast the basic object into a more strongly typed class which knows what properties to expect. The basic top level class is as follows: using System;
8
8921
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it. Like, for instance the Objective-C method: +(void)initialize Which has the following characteristics: It is guaranteed to be run
5
8605
by: Rainer Queck | last post by:
Hello NG, Is it possible to share the settings of an application with a class libreary? In my case I have a application and a set of different reports (home made) put into a class library. The plan is to delivere different report.dlls with the main app. But it is essentially importent, that the reports and the app use the same settings.
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8631
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...
0
8490
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
7174
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...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
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
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.