?
Solved

What are disadvantages of Auto-implemented properties over Normal properties in C# / VB.NET

Posted on 2011-04-23
5
Medium Priority
?
957 Views
Last Modified: 2013-12-16
Hi,

Can you please let me know in simple terms:

What are disadvantages of Auto-implemented properties over Normal properties in C# / VB.NET

Thanks
0
Comment
Question by:milani_lucie
5 Comments
 
LVL 16

Assisted Solution

by:Imran Javed Zia
Imran Javed Zia earned 500 total points
ID: 35454446
There are not many, but few are:

If you have to apply some custom login in set or get then you cannot do that

It is ambigous for new persons (rare in practive)

Your code will not be backword compatible (minnor issue, very rare in practice)

thanks
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35455254
To expand on IJZ's third point, auto-implemented properties do not exist in pre-4.0 VB. They do exist in 3.0+ C#, however.
0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 500 total points
ID: 35455827
the only limitation rather than disadvantage that i could figure out is that there has to be both getter and setter implemented. you cannot have one of them.
0
 
LVL 5

Assisted Solution

by:andr_gin
andr_gin earned 500 total points
ID: 35456300
1.) Auto implementing properties require to target .NET 4.0. If you run your software on more than one computer, try to target .NET 2.0.
2.) You cannot set them ReadOnly
3.) You can access the backing field with Me._PropertyName or this._PropertyName, but it is hidden from IntelliSense
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35456338
the only limitation rather than disadvantage that i could figure out is that there has to be both getter and setter implemented. you cannot have one of them.
However, you don't have to make them public. It is completely fine to do something like:

public string MyString { get; private set; }

Open in new window


to simulate a read-only property (the "write" is only accessible within the class itself), or

public string MyString { private get; set; }

Open in new window


to simulate a write-only property (the "read" is only accessible within the class itself).

You can't, however, make both "get" and "set" private--this will give a compiler error.

Auto implementing properties require to target .NET 4.0.
Not entirely true. See post above: http:#35455254.

You can access the backing field with Me._PropertyName or this._PropertyName, but it is hidden from IntelliSense
Why would you want to? If you're going to access the backing field, you might as well create a private variable. At least this would be more intuitive to coders coming behind you.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question