.net - Public Properties and Private Members C# -


What is the benefit of public properties rather than using public property to reach a private variable?

For example

  public int iMyInt {get; Set; }  

instead of

  private instant mounts; Public Int iMyInt {back {myint; } Set {myint = value; }}  

In addition to managing the variable / memory under property, what are the advantages (or the disadvantages of that case)?

Using automatic properties (first instance) requires less typing.

This is only recommended for public properties and not public sector. Many properties have simple wrappers around private areas. Automatic properties allow you to manually save the time and difficulty of the property and banking field.

For the simple case you mentioned, the actual code behind automated and manual properties should be almost the same.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -