473,320 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

AutoImplemented Properties

As I read, one of the advantage of implementing auto-Implemented
Properties is to avoid the accidental access/ modification of the
private variable in the class.

However If set or get needs to be customized(as per the class logic),
there is no option I see, other than writing the private variable
again.

In which case, it can only be useful for the extendibility of public
variables to be converted into properties in the future.

I see no advantage over the public variables.

Is there any other major factor, which drove the implementation of
auto-Implemented properties in .Net3.0 ???

Thanks in advance

-Srinivas
Nov 16 '08 #1
3 2160
You seem to believe that you should have auto-implemented properties, or
public fields, but not regular public properties with backing variables such
as below:

private string _name;
public string Name {
get {return _name;}
set {_name = value;}
}

A reason for properties is that they can be used for databinding in
controls, where fields cannot, to the best of my knowledge.

"Duggi" <Du***************@gmail.comwrote in message
news:6b**********************************@c36g2000 prc.googlegroups.com...
As I read, one of the advantage of implementing auto-Implemented
Properties is to avoid the accidental access/ modification of the
private variable in the class.

However If set or get needs to be customized(as per the class logic),
there is no option I see, other than writing the private variable
again.

In which case, it can only be useful for the extendibility of public
variables to be converted into properties in the future.

I see no advantage over the public variables.

Is there any other major factor, which drove the implementation of
auto-Implemented properties in .Net3.0 ???

Thanks in advance

-Srinivas
Nov 16 '08 #2
On Sun, 16 Nov 2008 11:29:22 -0800, Duggi <Du***************@gmail.com>
wrote:
As I read, one of the advantage of implementing auto-Implemented
Properties is to avoid the accidental access/ modification of the
private variable in the class.

However If set or get needs to be customized(as per the class logic),
there is no option I see, other than writing the private variable
again.

In which case, it can only be useful for the extendibility of public
variables to be converted into properties in the future.

I see no advantage over the public variables.

Is there any other major factor, which drove the implementation of
auto-Implemented properties in .Net3.0 ??? [...]
You'd have to ask the language designers to be sure what their main goal
was. But it seems to me you've identified the main reason for having
auto-implemented properties: encouraging developers to write
"future-resistant" code (there's no such thing as "future-proof" :) ).

That is, auto-implemented properties make it that much simpler to write
things that act like properties as actual properties. Then in the future,
if a more complex implementation is needed, it can be added without
necessarily having to recompile all the dependent code.

Pete
Nov 16 '08 #3
On Nov 16, 12:39*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Sun, 16 Nov 2008 11:29:22 -0800, Duggi <DuggiSrinivasa...@gmail.com*
wrote:
As I read, one of the advantage of implementing auto-Implemented
Properties is to avoid the accidental access/ modification of the
private variable in the class.
However If set or get needs to be customized(as per the class logic),
there is no option I see, other than writing the private variable
again.
In which case, it can only be useful for the extendibility of public
variables to be converted into properties in the future.
I see no advantage over the public variables.
Is there any other major factor, which drove the implementation of
auto-Implemented properties in .Net3.0 ??? [...]

You'd have to ask the language designers to be sure what their main goal *
was. *But it seems to me you've identified the main reason for having *
auto-implemented properties: encouraging developers to write *
"future-resistant" code (there's no such thing as "future-proof" :) ).

That is, auto-implemented properties make it that much simpler to write *
things that act like properties as actual properties. *Then in the future, *
if a more complex implementation is needed, it can be added without *
necessarily having to recompile all the dependent code.

Pete
Thanks Pete. I was checking if I was on the right learning track or
not.

Thanks for the reply.

-Cnu
Nov 17 '08 #4

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

Similar topics

8
by: Paul | last post by:
Hello, I've been reading up on security in Java Applets and whilst I understand the concept, I can't successfully get my applet to read a file on my local machine. I discovered from...
2
by: Rick Austin | last post by:
I recently had to perform a reinstalltion of Windows XP (my registry seems to have become corrupt). After this completed I had to reinstall all applications since most use the registry for settings,...
9
by: kj | last post by:
Is there any way to programmatically discover and inspect *all* the properties of an object, even those that are not enumerable through a for/in loop? Thanks! kj -- NOTE: In my address...
4
by: Lyn | last post by:
Hi, This question may seem a bit academic... To learn more about Access VBA, I have been enumerating the properties of various form controls. This was mostly successful and I have learned a lot...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
7
by: Anderskj | last post by:
Hi! I am developing a c# application. I have a interface (which can change therefore my problem) If i do like this: List<PropertyInfoproperties = new List<PropertyInfo>();...
0
by: =?Utf-8?B?UmljayBHbG9z?= | last post by:
For some unknown reason (user error?), I cannot get a NameValueCollection to persist in the app.config file. Unlike other settings, I cannot get the String Collection Editor GUI to allow my to...
4
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.