Class property persistence in Visual Studio vs Visual Studio.net

This question is about properties added to classes in Visual Studio-Classic vs. Visual Studio.net:
I have been following some examples on building classes and it appears one of the major differences between classes in VS-Classic vs. VS.Net is that one of the built in features of .Net is that the properties of classed will persist(hold) any values assigned to them as opposed to VS-Classic where code need to be written to store and return and values assigned "Let" or retrieved "Get".  

Just wanted to know if someone could elaborate on this and let me know if this was a feature that can be enabled in VS-Classic or VBA ?   Can the feature be disabled in VS.Net ?
Has it been there all these years in VS.Classic and our team never did take advantage of it ?

Any help is appreciated.
Thanks
sidwelleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Wrong.  
I think what you mean is the possibility of automatically generating get and set accessors (nothing to do with persisting values) which is in .net
Fernando SotoRetiredCommented:
To your question, "Just wanted to know if someone could elaborate on this and let me know if this was a feature that can be enabled in VS-Classic or VBA ? ", No it is not a even supported in VB Classic.

To your question, "Can the feature be disabled in VS.Net ?", The functionality of Properties is part of the language and can not be disabled. If you want to you can choose not to use them and just use Fields, values defined at class level but then that defeats the purpose of OOP programming.  

To your question, "Has it been there all these years in VS.Classic and our team never did take advantage of it ?", As stated above it is not part of Classic, so no.
Jacques Bourgeois (James Burger)PresidentCommented:
In recent versions of the framework, you have 2 ways to define a property.

Public Property Value As Integer

Open in new window


or

	Private _Data As Integer

	Public Property Data As Integer
		Get
			Return _Data
		End Get
		Set(value As Integer)
			_Data = value
		End Set
	End Property

Open in new window


The first one, the new one for you, is more convenient to use when you have nothing special to do either in the Get or the Set. In the background, the compiler generates exactly the same code as the same one, up to the private variable with the underscore.

If however you need some validation or transformation either in the getter or the setter, then you would use the second one:

	Private _Data As Integer

	Public Property Data As Integer
		Get
			Return _Data
		End Get
		Set(value As Integer)
			If value > 100 Then
				Throw New Exception("Invalid value")
			Else
				_Data = value
			End If
		End Set
	End Property

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

sidwelleAuthor Commented:
Here is an example of what I am talking about. Notice that clsStyle01 and clsStyle02 behave exactly the same. In clsStyle01 no code was needed to persist the values ??
Is this feature available in VB.Net or VB.Classic ?

Thanks

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            clsStyle01 myStyle = new clsStyle01();
            //clsStyle02 myStyle = new clsStyle02();

            myStyle.Size = 1;
            myStyle.Color = 2;
            myStyle.Weight = 3;

            MessageBox.Show(
                "Size: " + myStyle.Size + "\r\n" +
                "Color: " + myStyle.Color + "\r\n" +
                "Weight: " + myStyle.Weight 
              );
        }
    }

    class clsStyle01
    {
        public int Size{ get; set;}
        public int Color{ get; set;}
        public int Weight{ get; set;}
    }

    class clsStyle02
    {
        int _iSize;
        int _iColor;
        int _iWeight;

        public int Size
        {
            get { return this._iSize; }
            set { this._iSize = value; }
        }

        public int Color
        {
            get { return this._iColor; }
            set { this._iColor = value; }
        }

        public int Weight
        {
            get { return this._iWeight; }
            set { this._iWeight = value; }
        }

    }

Open in new window

Jacques Bourgeois (James Burger)PresidentCommented:
Yes, what I gave you before:

Public Property Size As Integer
Public Property Color As Integer
Public Property Weight as Integer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
That is what I said in the first comment.  In .net you can automatically generate accessors.  Note as I also said this is nothing to do with persisting values.
AndyAinscowFreelance programmer / ConsultantCommented:
Values/variables persisting, consider the following:

if(true)
{
  int a = 12;
  DoSomething(a);     This is OK, a exists
  DoSomethingElse(a);   This is still OK, a exists
}
DoSomethingElseAgain(a);    //Error - a does not exist, a only persists within the if construct scope
sidwelleAuthor Commented:
Let me do some testing today and get back.

Thanks
sidwelleAuthor Commented:
James:  Sorry for not reading your first post more closely.  I did find the you can declare the properties with one line effectively making it a structure in the new version of VS.  

C#'13    Yes; VB'13    Yes; C# '08   Yes; VB '08   No; VB6    No

Andy:  Now that I have some more info, my question should read "how to generate Properties w/o the accessor block",  The MS definition states:
"accessor-bodyThe block that contains the statements to be executed when the accessor is invoked."

Last Question:  Is there a specific name for this type of short hand property notation ?

Thank you.
AndyAinscowFreelance programmer / ConsultantCommented:
>>Last Question:  Is there a specific name for this type of short hand property notation ?

Erm:- accessors.   (Or getter and setter for the individual ones.  It doesn't make any difference to the naming if they are the automatically generated ones or ones you code yourself).
Jacques Bourgeois (James Burger)PresidentCommented:
They are called Auto-implemented properties.
sidwelleAuthor Commented:
Thanks James.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.